-2
Hello,
I need to show the date 00-00-0000 as I do in this code below?
<span data-bind="text: created_at"></span>
I appreciate any help
-2
Hello,
I need to show the date 00-00-0000 as I do in this code below?
<span data-bind="text: created_at"></span>
I appreciate any help
2
To use this date pattern, you can use PHP’s native function, the Date or the Carbon (standard class that Laravel uses for date), which is already installed in Laravel.
In the control use as example the code below. Add $user->created_at->format("d-m-Y")
. Ex:
public function index()
{
$reviews = \App\Reviews::all();
return view('home', ["reviews" => $reviews]);
}
In the view use
@foreach ($reviews as $review)
<span data-bind="text: {{ $review->created_at->format("d-m-Y") }}"></span>
@endforeach
If you want to change the format, simply replace d-m-Y by any of the following table values: http://br.php.net/manual/en/function.date.php
Browser other questions tagged php laravel
You are not signed in. Login or sign up in order to post.
Hello Valdeir, thank you. but giving the following error Undefined variable: created_at
– user100984
Are you using Lade? You are passing the variable
created_at
in an array for the view? If possible edit your question with snippets of your code.– Valdeir Psr
Yes, Blade , I put it as directed public Function index() { $users = Reviews:::all(); Return view('user.index', pact('Reviews')); $user = App User::find(1); $data["created_at"] = $user->created_at->format("d-m-Y"); Return view('home', $data); } in Blade <span data-bind="text: {{ $created_at }}></span>
– user100984
@Toninho, I changed my example.
– Valdeir Psr
Undefined variable: Views
– user100984
@Toninho, you need to adapt my example to your code. As I do not have the source code of your project, I can only analyze superficially. If possible edit your question with part of its source code. This error is in view, controller... ?
– Valdeir Psr
I put in the index.blade.php view just like you gave me. The error is in index.blade.php
– user100984
I changed my answer, if possible check again.
– Valdeir Psr
part of index.Blade <Section data-bind="foreach: {data: sourceItems, afterRender: lazyLoadImage}" class="col-Sm-8"> Published: <span data-bind="text: created_at"></span><br>
– user100984
Undefined variable: Views
– user100984
Posta his
view
in your question (and not just a line from it), but it is difficult. It is so much that you are probably usingknockoutjs
(or similar) and did not make it clear in the question. Only assimilei now. Without information there is much to help.– Valdeir Psr