2
I have a record table with a field id_user
, this table has data entered by some system user. I need that when the user authenticates in the system, only see the records that he created. That is, the records that have the id_user = id
authenticated user.
Created Table
Schema::create('webinars', function (Blueprint $table) {
$table->increments('id');
$table->integer('id_user')->unsigned();
$table->foreign('id_user')->references('id')->on('users');
$table->string('name', 255);
$table->text('description');
$table->dateTime('create_date');
$table->time('time_duration');
$table->timestamps();
});
Route
Route::group(['middleware' => 'web'], function()
{
Auth::routes();
Route::get('/', 'HomeController@index');
Route::get('/webinar/gerenciarwebinar', 'GwebinarController@index');
});
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Webinar;
class GwebinarController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$webinars = \App\Webinar::all();
return view('webinar.gwebinar', compact('webinars'));
}
}
Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Webinar extends Model
{
//
}
View
@foreach($webinars as $webinar)
<tr>
<td>{{ $webinar->name }}</td>
<td>{{ $webinar->create_date }}</td>
<td>{{ $webinar->time_duration }}</td>
<td><a href="" type="button" class="btn btn-sm btn-secondary margin-inline">@lang('webinario.lang08')</a></td>
<td><a href="" type="button" class="btn btn-sm btn-secondary margin-inline">@lang('webinario.lang09')</a></td>
<td>
<div class="dropdown margin-inline">
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
@lang('webinario.lang10')
</button>
<ul class="dropdown-menu" aria-labelledby="" role="menu">
<a class="dropdown-item" href="javascript: void(0)">
<i class="left-menu-link-icon icmn-pencil2"><!-- --></i> @lang('webinario.lang12')</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item swal-btn-warning" href="javascript: void(0)"><i class="left-menu-link-icon icmn-bin"><!-- --></i>
@lang('webinario.lang13')</a>
</ul>
</div>
</td>
</tr>
@endforeach
you could put your Model? you could make available what you have done so far?
Eloquent
orDB
?– novic
Thank you for the reply Virgilio. Follow the codes. My View is bringing all the records from the table webinars.
– Bruno Oliveira
I already made an answer!
– novic