Still error display: Missing required parameter - laravel

I facing the issue Missing required parameter for [Route: search.customer] [URI: agency/{slug}] [Missing parameter: slug]
Here is below my code
Route::get('/agency/{slug}', [SearchController::class, 'listing'])->name('search.customer');
#if ($agents->isNotEmpty())
#foreach ($agents as $value)
View More
#endforeach
#endif

Related

(Laravel) Missing required parameter for [Route:]

I have this issue: and im stuck i dont know what to do
Missing required parameter for [Route: bedrijven.delete] [URI: admin/bedrijven/{bedrijf}/delete] [Missing parameter: bedrijf].
my index page
<td> <a href= {{route('bedrijven.delete', ['bedrijven'=>$bedrijf->id])}}>Verwijder</a> </td>
my controller
{
return view('admin.bedrijven.delete', compact('bedrijf'));
}```
my route
```Route::get('admin/bedrijven/{bedrijf}/delete',[BedrijfController::class, 'delete'])
->name('bedrijven.delete');
Route::resource('/admin/bedrijven', BedrijfController::class);```

Missing required parameters for [Route: about]

I installed cviebrock/eloquent-sluggable package.
I have an issue with the URLs i.e., with the hrefs and slug.
menu.blade.php
<a class="nav-link" href="{{ route('about') }}">
web.php
Route::get('content/{contentSlug}', 'PageController#content')->name('about');
RouteServiceProvider.php
Route::bind('contentSlug', function ($value) {
return Page::whereSlug($value)->firstOrFail();
});
I get this error
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameters for [Route: about] [URI: en/content/{contentSlug}]. (
This is because you don't pass {contentSlug} value in route.
<a class="nav-link" href="{{ route('about',['contentSlug' =>'Hello']) }}">
If you want to make route with optional parameter then use ? .{contentSlug?}

laravel 7 route/url param in Blade

I tried to pass parameter type=Business via GET request to
RegisterForm.
In Welcome.blade
I have two links to RegisterForm.
#if (Route::has('register'))
Register Business
Register Applicant
#endif
In RegisterForm, I have hidden field like this:
#if (isset($type))
<input id="userType" type="hidden" class="form-control" name="userType" value="{{ $type }}">
#endif
Even Tried this way:
#if (isset($type == 'Business'))
<input id="userType" type="hidden" class="form-control" name="userType" value="{{ $type }}">
#endif
In Laravel side: Main page gets userTypes via:
public function index()
{
$userTypes = array(
'Applicant',
'Business'
);
return view('website::welcome', compact('userTypes'));
}
return view('website::welcome'
means I have own package called "website".
Q) What do I missing, what is wrong my code ?
I am getting error from registerForm:
ParseError
syntax error, unexpected '$type' (T_VARIABLE), expecting ',' or ')' (View: register.blade.php)
The error is comming from this below line.
#if (isset($type == 'Business'))
You need to call two conditions as below. for isset and comparison
#if (isset($type) && $type== 'Business')

Laravel #foreach and #forelse

I have a problem with my view of laravel. I have a field that executes a loop, and if it has data in the field it list, but if it does not it only shows me nothing.
I used #forelse but it does not work, any help?
with $prices I can check whether or not it has the value, but in that fieldinfos_home does not.
I used #forelse but it does not work, any help?
<em>{{ $prices->price ?? ' - ' }}</em> <br>
#forelse($prices->infos_home as $info)
<em>{{ $info }}</em> <br>
#empty
<em> - </em>
#endforelse
When I use #forelse I have the following error message.
message: "Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: Trying to get property 'infos_home' of non-object (View: C:\wamp64\www\suzuki-cms-backoffice\resources\views\brand\motorcycle\variations\index\column-price.blade.php)"
KISS and just use #if / #else:
<em>{{ $prices->price ?? ' - ' }}</em> <br>
#if($prices && $prices->infos_home)
#foreach($prices->infos_home as $info)
<em>{{ $info }}</em> <br>
#endforeach
#else
<em> - </em>
#endif
#forelse is good when you are sure that variable exists.

Laravel Redirect Back with() Message

I am trying to redirect to the previous page with a message when there is a fatal error.
App::fatal(function($exception)
{
return Redirect::back()->with('msg', 'The Message');
}
In the view trying to access the msg with
Sessions::get('msg')
But nothing is getting rendered, am I doing something wrong here?
Try
return Redirect::back()->withErrors(['msg' => 'The Message']);
and inside your view call this
#if($errors->any())
<h4>{{$errors->first()}}</h4>
#endif
Laravel 5 and later
Controller
return redirect()->back()->with('success', 'your message,here');
Blade:
#if (\Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{!! \Session::get('success') !!}</li>
</ul>
</div>
#endif
Alternative approach would be
Controller
use Session;
Session::flash('message', "Special message goes here");
return Redirect::back();
View
#if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
#endif
In Laravel 5.4 the following worked for me:
return back()->withErrors(['field_name' => ['Your custom message here.']]);
You have an error (misspelling):
Sessions::get('msg')// an extra 's' on end
Should be:
Session::get('msg')
I think, now it should work, it does for me.
Just set the flash message and redirect to back from your controller functiion.
session()->flash('msg', 'Successfully done the operation.');
return redirect()->back();
And then you can get the message in the view blade file.
{!! Session::has('msg') ? Session::get("msg") : '' !!}
In Laravel 5.5:
return back()->withErrors($arrayWithErrors);
In the view using Blade:
#if($errors->has())
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif
In laravel 5.8 you can do the following:
return redirect()->back()->withErrors(['name' => 'The name is required']);
and in blade:
#error('name')
<p>{{ $message }}</p>
#enderror
For Laravel 5.5+
Controller:
return redirect()->back()->with('success', 'your message here');
Blade:
#if (Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{{ Session::get('success') }}</li>
</ul>
</div>
#endif
in controller
For example
return redirect('login')->with('message',$message);
in blade file
The message will store in session not in variable.
For example
#if(session('message'))
{{ session('message') }}
#endif
I stopped writing this myself for laravel in favor of the Laracasts package that handles it all for you. It is really easy to use and keeps your code clean. There is even a laracast that covers how to use it. All you have to do:
Pull in the package through Composer.
"require": {
"laracasts/flash": "~1.0"
}
Include the service provider within app/config/app.php.
'providers' => [
'Laracasts\Flash\FlashServiceProvider'
];
Add a facade alias to this same file at the bottom:
'aliases' => [
'Flash' => 'Laracasts\Flash\Flash'
];
Pull the HTML into the view:
#include('flash::message')
There is a close button on the right of the message. This relies on jQuery so make sure that is added before your bootstrap.
optional changes:
If you aren't using bootstrap or want to skip the include of the flash message and write the code yourself:
#if (Session::has('flash_notification.message'))
<div class="{{ Session::get('flash_notification.level') }}">
{{ Session::get('flash_notification.message') }}
</div>
#endif
If you would like to view the HTML pulled in by #include('flash::message'), you can find it in vendor/laracasts/flash/src/views/message.blade.php.
If you need to modify the partials do:
php artisan view:publish laracasts/flash
The two package views will now be located in the `app/views/packages/laracasts/flash/' directory.
Here is the 100% solution
*Above mentioned solutions does not works for me but this one works for me in laravel 5.8:
$status = 'Successfully Done';
return back()->with(['status' => $status]);
and receive it as:
#if(session()->has('status'))
<p class="alert alert-success">{{session('status')}}</p>
#endif
It works for me and Laravel version is ^7.0
on Controller
return back()->with('success', 'Succesfully Added');
on Blade file
#if (session('success'))
<div class="alert alert-success">
{!! session('success') !!}
</div>
#endif
For documentation look at Laravel doc
I know this is an old post but this answer might help somebody out there.
In Laravel 8.x this is what worked for me: You can return the error to the previous page or to another page.
return Redirect::back()->withErrors(['password' => ['Invalid Username or Password']]);
This will also work:
return view('auth.login')->withErrors(['username' => ['Invalid Username or Password']]);
Please ENSURE, however, that the page/view you are returning has a field name that corresponds to the first parameter passed in the withErrors method (in this case, username or password) and that the #error directive in your view references the same field like this
#error('password') //or #error('username')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
for example
Hope this helps somebody. Cheers.
#Laravel-9
Inside the blade where this redirection back action initiated
return redirect()->back()->with('message', "The Message");
Inside the blade where this form, will be returned after the above action
#if(session()->has('message'))
<p class="alert alert-success"> {{ session()->get('message') }}</p>
#endif
For laravel 5.6.*
While trying some of the provided answers in Laravel 5.6.*, it's clear there has been some improvements which I am going to post here to make things easy for those that could not find a solution with the rest of the answers.
STEP 1:
Go to your Controller File and Add this before the class:
use Illuminate\Support\Facades\Redirect;
STEP 2:
Add this where you want to return the redirect.
return Redirect()->back()->with(['message' => 'The Message']);
STEP 3:
Go to your blade file and edit as follows
#if (Session::has('message'))
<div class="alert alert-error>{{Session::get('message')}}</div>
#endif
Then test and thank me later.
This should work with laravel 5.6.* and possibly 5.7.*
I faced with the same problem and this worked.
Controller
return Redirect::back()->withInput()->withErrors(array('user_name' => $message));
View
<div>{{{ $errors->first('user_name') }}}</div>
In blade
#if(Session::has('success'))
<div class="alert alert-success" id="alert">
<strong>Success:</strong> {{Session::get('success')}}
</div>
#elseif(session('error'))
<div class="alert alert-danger" id="alert">
<strong>Error:</strong>{{Session::get('error')}}
</div>
#endif
In controller
for success
return redirect()->route('homee')->with('success','Successfully Log in ');
for error
return back()->with('error',"You are not able to access");
laravl 8
Route::post('/user/profile', function () {
// Update the user's profile...
return redirect('/dashboard')->with('status', 'Profile updated!');
});
Blade syntax
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
enter link description here
For Laravel 3
Just a heads up on #giannis christofakis answer; for anyone using Laravel 3 replace
return Redirect::back()->withErrors(['msg', 'The Message']);
with:
return Redirect::back()->with_errors(['msg', 'The Message']);
Laravel 5.6.*
Controller
if(true) {
$msg = [
'message' => 'Some Message!',
];
return redirect()->route('home')->with($msg);
} else {
$msg = [
'error' => 'Some error!',
];
return redirect()->route('welcome')->with($msg);
}
Blade Template
#if (Session::has('message'))
<div class="alert alert-success" role="alert">
{{Session::get('message')}}
</div>
#elseif (Session::has('error'))
<div class="alert alert-warning" role="alert">
{{Session::get('error')}}
</div>
#endif
Enyoj
I got this message when I tried to redirect as:
public function validateLogin(LoginRequest $request){
//
return redirect()->route('sesion.iniciar')
->withErrors($request)
->withInput();
When the right way is:
public function validateLogin(LoginRequest $request){
//
return redirect()->route('sesion.iniciar')
->withErrors($request->messages())
->withInput();
Laravel 5.8
Controller
return back()->with('error', 'Incorrect username or password.');
Blade
#if (Session::has('error'))
<div class="alert alert-warning" role="alert">
{{Session::get('error')}}
</div>
#endif
**Try This**
Try This Code
--- Controller ---
return redirect('list')->with('message', 'Successfully');
return redirect('list');
---- Blade view ------
#if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
#endif

Resources