This is my alert.blade.php file
@if ($errors->any())
<div>
<ul>
@foreach ($errors->all() as $error)
<li style="color: red">{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@if (Session::has('error'))
<div>
<ul>
<li style="color: red">{{ Session::get('error') }}</li>
</ul>
</div>
@endif
@if (Session::has('success'))
<div>
<ul>
<li style="color: green">{{ Session::get('success') }}</li>
</ul>
</div>
@endif
When run code the brower: Class "Session" not found. But yesterday it still work, today I clone code again but this error was show. I dont remember how to solve this. Please help
And dashboard met same kind of error
@foreach ($products as $product)
<a href="/products/view/{{ $product->id }}" >
<div >
<div >
<img src="{{ $product->thumb }}">
</div>
<div >
<h2 >{{ /Str::title($product->name) }}
</h2>
@if ($product->price > $product->sale_price)
<div >
<h2 >
<p >{{ /Str::title($product->price) }}$</p> -> <p
>{{ /Str::title($product->sale_price) }}$</p>
</h2>
</div>
@else
<h2 >
{{ /Str::title($product->price) }}$
</h2>
@endif
</div>
<div >
<h2 >0 star | 0 sale
</h2>
</div>
</div>
</a>
@endforeach
CodePudding user response:
You can use Laravel's session helper function like this
@if (session()->has('error'))
<div>
<ul>
<li style="color: red">{{ session()->get('error') }}</li>
</ul>
</div>
@endif
@if (session()->has('success'))
<div>
<ul>
<li style="color: green">{{ session()->get('success') }}</li>
</ul>
</div>
@endif
or you can also do this
@if (Illuminate\Support\Facades\Session::has('error'))
<div>
<ul>
<li style="color: red">{{ Illuminate\Support\Facades\Session::get('error') }}</li>
</ul>
</div>
@endif
@if (Illuminate\Support\Facades\Session::has('success'))
<div>
<ul>
<li style="color: green">{{ Illuminate\Support\Facades\Session::get('success') }}</li>
</ul>
</div>
@endif
And for the Str
error you can do the same
{{ Illuminate\Support\Str::title($product->name) }}
{{ Illuminate\Support\Str::title($product->price) }}
// and so on....
CodePudding user response:
Use
\Illuminate\Support\Str::
\Illuminate\Support\Arr::
et cetera