Trying to access from Controller values to my blade
public function show(Template $template){
if (Save::where('user_id', '=', auth()->user()->id)->count() > 0) {
if (Save::where('title', '=', $template->title)->count() > 0) {
//OUTPUT - EXISTS
}
//OUTPUT - NOT EXISTS
}
return view('actions/show', [
'template' => $template
]);
}
How am I able to call these if statement value in show.blade.php, so I be able to make from this:
<form action="/save/{{$template->unique_key}}" method="POST">
@csrf
@method('PUT')
<button><i class="bi bi-heart-fill"></i></button>
</form>
To this
if($save == 'notExists')
<form action="/save/{{$template->unique_key}}" method="POST">
@csrf
@method('PUT')
<button><i class="bi bi-heart-fill"></i></button>
</form>
@else
ALREADY SAVED
@endif
3
Answers
In your controller file. You have to have an
if-else
statement as well as assign a variable.In your controller, change your code to this.
Now in your view file you can access it this way
This can be shortened:
show.blade.php
Modify your code as below. you are using same query multiple time.
In blade it will be like this.