Reputation: 411
I am doing a blog project in laravel. i want to retrieve time of a specific post. In laravel there is a function in table called timestamp(). Can I use it for this purpose.I tried several ways but it didn't work,Can anyone help?
post_table:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
home.blde.php file:
<tbody>
@foreach($posts as $post)
<tr>
<td> {{ $post->title }} </td>
<td>Edit</td>
<!-- <td>Delete</td> -->
<!-- $time= $post->timestamps->('created_at') -->
<td>{{ $post->timestamps() }}</td>
<!-- <td>{{$time}}</td> -->
</tr>
@endforeach
</tbody>
Upvotes: 0
Views: 525
Reputation: 156
timestamps() is not Eloquent method and to get both created and updated dates you can do like this:
For Created Timestamp:
<td>{{ $post->created_at }}</td>
For Updated Timestamp:
<td>{{ $post->updated_at }}</td>
Upvotes: 1
Reputation: 13394
In your model Post, if you don't define the function timestamps
, it will not works.
Because timestamps()
is the method of Illuminate\Database\Schema\Blueprint
,
Take a look at here;
And in your migration, timestamps()
will generates two columns created_at
and updated_at
by default;
I think you just want to call one of them, like:
<td>{{ $post->created_at }}</td>
Upvotes: 1