I have a records table with a id_user
field, in this table there are data entered by some users of the system. I need when the user authenticates in the system, only see the records that he created. That is, records that have id_user = id
of the 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