Im confused how to get the created_at
column in my pivot
table. I have exam_user
table with created_at
and updated_at
column. Now, I have this code in my view:
@if($exam->users()->where('user_id', Auth::user()->id)->exists())
{{ Auth::user()->assignments()->pivot->created_at }}
<div class="alert alert-success">You have done with this exam.</div>
@else
Any idea for this?
In laravel, When working in a many-many relationship, the user has to choose the intermediate table and it is called a pivot table in terms of Laravel. The pivot attribute communicates with this intermediate table in controllers or models in Laravel. The admin in laravel has to define the role of every other user.
Laravel's naming convention for pivot tables is snake_cased model names in alphabetical order separated by an underscore. So, if one model is Feature , and the other model is Product , the pivot table will be feature_product .
You have to run - php artisan make:migration create_project_user_table --create --table=project_user to create the pivot table migration file after that you can copy/paste code in this migration file and run migrate command to create pivot table in your database.
When setting up your relationships, you need to specify if that pivot table has timestamps.
public function things() {
return $this->belongsToMany('App\Thing')->withTimestamps();
}
Edit:
try Auth::user()->assignments()->first()->pivot->created_at
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With