Reputation: 39
I am working with laravel to check the post request and then show the alert in the same page. i tried to return the last url using back with a message but i am unable to see the message.
This is my controller function
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use App\Category;
use App\Glassfilm;
use DB;
use Session;
public function checkProduct(Request $request){
$this->validate($request,[
'area' => 'required',
]);
if($request->area <= $request->stock){
//echo "the product is available";
//echo $request;
//Session::flash('message', "available");
echo back();
// return back()->with(['success' => 'Success']);
}
else{
echo "the product is not available";
echo $request;
}
// echo $request;
}
My route
Route::get('/glassfilm/{name}/{id}' , 'GlassFilmController@search_by_id');
Route::post('/checkproduct' , 'GlassFilmController@checkProduct')->name('check-product');
my view
@extends ('glassfilm.master')
@section ('title')
{{$name}}
@endsection
@section('message')
@if(Session::has('success'))
<div class="alert alert-success" role="alert">
{{ Session::get('success') }}
</div>
@endif
@endsection
@section ('category')
<ul class="main-categories">
@foreach($category as $category)
<li class="main-nav-list"><a href="{{url('/glassfilm/'.$category->category)}}">{{ $category->category }}<span class="number">({{ $category->count}})</span></a></li>
@endforeach
</ul>
@endsection
@section ('glassfilm')
<section class="lattest-product-area pb-40 category-list">
<div class="row">
<!-- single product -->
@foreach($filterResult as $glass)
<div class="col-lg-3 col-md-6">
<div class="single-product">
@foreach(json_decode($glass->image) as $key=>$image)
@if($loop->first)
<a href="{{url('/glassfilm/'.$category->category.'/'.$glass->id)}}"><img class="img-fluid" src="{{asset('storage')}}/{{$image}}" alt="" style=" width: 263px; height: 280px "></a>
@endif
@endforeach
<div class="product-details">
<h6>{{ $glass->name }}</h6>
<div class="price">
<h6>₹{{ $glass->price - ($glass->price * $glass->discount )/100 }}/sqft</h6>
<h6 class="l-through"> ₹{{ $glass->price }}/sqft</h6>
</div>
<div class="prd-bottom">
<a href="" class="social-info">
<span class="ti-bag"></span>
<p class="hover-text">add to bag</p>
</a>
<a href="" class="social-info">
<span class="lnr lnr-move"></span>
<p class="hover-text">view more</p>
</a>
</div>
</div>
</div>
</div>
@endforeach
<!-- single product -->
</div>
</section>
@endsection
Upvotes: 2
Views: 1561
Reputation: 3704
Please Try this
return redirect()->back()->with('success', 'Success');
@if ($message = Session::get('success'))
<div class="alert alert-success" role="alert">
{{ $message }}
</div>
@endif
Upvotes: 0
Reputation: 2945
If you can show your validate
error then place the following block in the blade file.
@if( count( $errors ) > 0 )
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.
<ul>
@foreach( $errors->all() as $error )
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
In controller
public function checkProduct(Request $request){
$this->validate($request,[
'area' => 'required',
]);
if($request->area <= $request->stock){
return redirect()->back()->with('success', 'The product is available');
}
else{
return redirect()->back()->with('success', 'The product is not available');
}
}
Upvotes: 0
Reputation: 1932
Use
return redirect()->back()->with('success', 'Success');
then in your blade.
@if (Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{{ Session::get('success') }}</li>
</ul>
</div>
@endif
Upvotes: 0
Reputation: 604
hi try to use this code on your blade
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
Upvotes: 0