Route not found even though It's defined - laravel

This is the error that I get rolled out
(View: Route [user.profile] not defined. (View: D:\Programi\XAMPP\htdocs\crushapp\resources\views\layouts\base.blade.php)
But my route is clearly defined here:
use App\Http\Livewire\User\ProfileComponent;
Route::middleware(['auth:sanctum','verified'])->group(function()
{
Route::get('/user/profile',ProfileComponent::class)->name('user.profile');
});
The error comes from the layout, namely:
<span><i class="fa fa-user-circle-o" aria-hidden="true"></i> {{ Auth::user()->name }}  ‎‎‏‏‎ ‎‎‏‏</span>
Any ideas what could it be?
UPDATE: Any new route I try defining under user won't work...

first you are missing a function name in your route
also run php artisan route:clear
Route::get('/user/profile',ProfileComponent::class, 'index')->name('user.profile')

Related

Laravel 404 not found when passing parameter with route()

Hello I have instructors table, and every instructor have name column and I have a page to show events and every event has instructor name and I need to go to the instructor profile page when clicking on the instructor name in the events page so I made this
<a href="{{ route('instructor.profile', ['name' => $event->instructor]) }}" class="a-reset">
<h5 class="color-primary fw-bold">{{ $event->instructor }}</h5>
</a>
web.php
Route::get('/instructor/{name}', 'App\Http\Controllers\InstructorController#profile')->name('instructor.profile');
InstructorController
public function profile($name) {
$instructor = Instructor::where('name', '=', $name)->first();
return view('instructor-profile', compact('instructor'));
}
But it gives me 404 Not Found error page
Make sure it returns value $event->instructor
Make sure the address is correct instructor-profile
by this command rtisan route:list open route list, make sure it is there /instructor/{name} route.
if everything is correct run this command
php artisan route:clear
php artisan config:cache

Laravel route returning error 404 when attempt is made to pass value to controller function

I have a button in my blade like this
#can('customer_show')
<a class = "btn btn-primary" href = "{{ route('admin.loan-applications.showCustView', $loanApplication->user_id) }}">
View Applicant
</a>
#endcan
And this is the route:
Route::get('loan-applications/{loan_application}/showCustView', 'loanApplicationsController#showCust')->name('loan-applications.showCustView');
And in my controller, i did:
public function showCust(LoanApplication $loanApplication)
{
$customerInformation = customerInfoModel::where('Cust_id', $loanApplication->user_id));
return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}
What i am trying to do is fetch the row from the database attached to customerInfoModel where the the Cust_id field equals the loanApplication->user_id of the loan being viewed currently in the blade above. When the button "view Applicant" is hit, i get an error 404 page. Why is that so?
Check it out the route list using this command
php artisan route:list
//this command will show all the routes in your application
If your route not listed on that route list checkout for routes with same Url on your route manually on routes file.
if you found change the url & use this command to clear cache
php artisan optimize:clear
i have found the comment of you on last answer.
check out for route model binding . i think you have to add
a
public function showCust( $loanApplicationCustId)
{
$customerInformation = customerInfoModel::where('Cust_id', $loanApplicationCustId))->first();
return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}
It should be like this .. i hope it works for you......
else share your project git repo link
I think it should be like following:
#can('customer_show')
<a class = "btn btn-primary" href = "{{ route('loan-applications.showCustView', $loanApplication->user_id) }}">
View Applicant
</a>
#endcan
try that

Missing required parameter on form action

First of all, I would like to say that my English is not so good and is my first time posting here, so excuse me if I did something wrong! Well, I am starting practicing with Laravel and I am trying to create a URL for users can like posts. my URL and controller is right now this Route::post('/post/{post}/like', [LikeController::class, 'postLike'])->name('post.like'); where post is the posts id that i am trying to pass through my form action attribute. Here is my form:
#props(['id'])
<div {{ $attributes->merge(['class' => 'card-footer d-flex justify-content-around']) }}>
<form action= "{{ route('post.like' , $id) }}" method="post" >
#csrf
<button>submit</button>
</form>
</div>
If you wonder if the id is not actually passed into the component, I checked {{ dd($id) }} and it printed it.
My controller is this which it doesn't actually do anything right now. I am just trying to pass the id:
class LikeController extends Controller
{
public function postLike(Post $post) {
dd($post);
}
}
After all this i am getting the error:
Missing required parameter for [Route: post.like] [URI: post/{id}/like] [Missing parameter: id]. (View: blog\resources\views\components\post\interaction.blade.php)
I am having two days to find the problem and I am still trying this moment I am sending this... I can't found where is the mistake! If you could help me would be much appreciated! Ty in advance
You need to pass the ID as an associative array in your route().
{{ route('post.like', ['id' => $id]) }}
If the named route defines parameters, you may pass the parameters as the second argument to the route function. The given parameters will automatically be inserted into the generated URL in their correct positions and you should name 'post' instead of 'id':
Route::post('/post/{post}/like', [LikeController::class, 'postLike'])->name('post.like');
And you can call this route anywhere
route('post.like', [$postId])
If that still doesn't work for you. Then it might be issue of Route Cache Run:
php artisan route:clear
Use same name parameter
When you use "id" keyword as a parameter in web.php then also same name pass in function argument in the controller
Route::post('/post/{id}/like', [LikeController::class, 'postLike'])->name('post.like');
Controller
class LikeController extends Controller
{
public function postLike(Post $id) {
dd($id);
}
}
Sorry for my bad English.
I have no idea this could be the problem but after many changes i cast the id of the post into an integer and it actually worked <form action= "{{ route('post.like' , (int)$id) }}" method="post" > . I don't know why i should cast the id into an integer because its already an integer by default and i checked that with {{ dd(getType($id)) }} and printed "integer"! I am really confused but it works! But i am not happy because i have no idea why i should cast an integer into an integer to make it work! Doesn't make any sense! If anyone has an answer to this would be great!

Route [admin/CountryController.store] not defined in Laravel

My CountryController is in admin folder which has store function.
Web.php is:-
Route::prefix('admin')->group(function () {
Route::resource('country', 'admin\CountryController');});
HTML Code is:-
<form method="post" action="{{ route('admin/CountryController.store') }}">
It's showing error:- Route [admin/CountryController.store] not defined. (View: C:\xampp\htdocs\happyvivah\resources\views\admin\country.blade.php)
use 'php artisan route:list' command in CMD. it will show the name of all route. it will show route name 'country.store'.
so after replacing to route('admin/CountryController.store') with route('country.store') it will work.

NotFoundHttpException in RouteCollection.php (line 179) dont fun

I have a problem in laravel, I have developed a system that worked correctly the routes, but now it does not work any route all give me the same result error.
Esta mi archivo app.blade.php
<li>
<a href={{url('home')}} class="dropdown-toggle">
<i class="fa fa-dashboard"></i>
<span class="hidden-xs">Panel</span>
</a>
</li>
This is my web.php file
Auth::routes();
Route::get('/', function () {
return view('home');
});
Route::get('/home', 'PruebaController#index')->name('home');
this is my Controller file
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PruebaController extends Controller
{
public function index()
{
return view('home');
}
}
php artisan route:list
I have reviewed everything but I do not find the problem, everything seems to be correct, what I did was to clone the project have something to do.
Dou yo have view->home.blade.php?
Since you mentioned that you have cloned the project, I think its got to do with cache.
Try
php artisan cache:clear
php artisan config:cache
I followed the error to the file RouteColletion.php in the function matchAgainstRoutes when I print the $ request, the last variables
Request {#38 ▼
...
pathInfo: "/ gesis / public / home"
requestUri: "/ gesis / public / home"
baseUrl: ""
basePath: ""
format: "html"
}
I leave empty I think that's why but I do not know why I leave these variables empty.
I corrected it thanks to all, the problem was the simple truth but I could not see the directive APP_NAME = geSis of the file .env changed the uppercase S by the small one so it did not encintrace the route.
I thanked them for their time and I received a lot of comments.

Resources