Reputation: 15
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 }}" class="m-4">
<div class="box-border h-{{ $h_box }} w-{{ $w_box }} p-4 border-4 justify-center rounded-md">
<div class="box-border h-{{ $image_size }} w-{{ $image_size }} border-1 mx-auto">
<img class="object-cover w-full h-full" src="{{ $product->thumb }}">
</div>
<div class="box-border h-16 w-{{ $image_size }} border-1 truncate mx-auto">
<h2 class="mt-1 font-medium leading-tight text-base mb-2">{{ /Str::title($product->name) }}
</h2>
@if ($product->price > $product->sale_price)
<div class="inline-block">
<h2 class="font-medium leading-tight text-base mt-0 mb-2 text-red-500">
<p class="line-through inline">{{ /Str::title($product->price) }}$</p> -> <p
class="inline">{{ /Str::title($product->sale_price) }}$</p>
</h2>
</div>
@else
<h2 class="font-medium leading-tight text-base mt-0 mb-2 text-red-500">
{{ /Str::title($product->price) }}$
</h2>
@endif
</div>
<div class="box-border h-16 w-{{ $image_size }} border-1 truncate mx-auto">
<h2 class="mt-1 text-left leading-tight text-base mb-2">0 star | 0 sale
</h2>
</div>
</div>
</a>
@endforeach
Upvotes: 0
Views: 897
Reputation: 145
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....
Upvotes: 1