Laravel 5.5 routes order error - laravel-5

I installed a fresh version of Laravel 5.5 and this is some issue with web routes ordering:
<?php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::group(['prefix' => 'respond'], function () {
Route::get('/{quiz}', 'RespondentController#show')
->middleware('auth');
Route::get('/save_answer2', 'RespondentController#save_answer2')
->middleware('auth');
});
route respond/save_answer2 - error 404
if we change the order of routing and route /save_answer2 will be above /{quiz} everything will be ok. Why is this?

Since you used prefix respond
Try respond/save_answer2

Related

Can't seem to find a way to use the route.php from 5.2 from laravel 5.2 to 8.83.25 web.php

I'm pretty new with Laravel, was able to work on finding a tutorial but it uses a
5.2 version.
I'm trying to convert the older version to 8.83.25
This is the route in the tutorial that I'm following.
I have created the CategoryController.php manually
Route::group(['middleware' => ['web']], function(){
Route::get('category', 'CategoryController');
});
What you used is wrong syntax. To pass a route to a controller, you are supposed to pass it as an array as such:
Route::group(['middleware' => ['web']], function(){
Route::get('category', [CategoryController::class]);
});
Now supposing you want to pass it to a particular function(lets say the function store) in your controller, you just indicate that in the array as such:
Route::group(['middleware' => ['web']], function(){
Route::get('category', [CategoryController::class, 'store']);
});
Take a look at the docs to learn more about laravel v8 routing.

Laravel use multiple subdomains in one app

My question can we use something like this in laravel routing like one routes for admin.domain.com and other routes for clients.domain.com. How achieve this in laravel routing.
For example:
// these needs to go clients.domain.com/route
Route::get('/clients', 'App\Http\Controllers\HomeController#index')->name('clients');
Route::get('/clients/order', 'App\Http\Controllers\KuponaiController#pridetiKupona')->name('clients.order');
//this one to admin.domain.com/admin
Route::get('/admin', 'App\Http\Controllers\KuponaiController#patvirtinimokodas')->name('dashboard');
There is clear documentation on how you can use subdomains in your Laravel application here https://laravel.com/docs/8.x/routing#route-group-subdomain-routing.
Route::domain('{account}.myapp.com')->group(function () {
Route::get('user/{id}', function ($account, $id) {
//
});
});
For this to work, you need to have this subdomain before registering root domain routes
Create a route group and pass an array with a domain property:
Route::group(['domain' => 'clients.domain.com'], function()
{
// clients.domain.com/clients
Route::get('/clients', 'App\Http\Controllers\HomeController#index')->name('clients');
// clients.domain.com/clients/order
Route::get('/clients/order', 'App\Http\Controllers\KuponaiController#pridetiKupona')->name('clients.order');
});
Route::group(['domain' => 'admin.domain.com'], function()
{
// admin.domain.com/admin
Route::get('/admin', 'App\Http\Controllers\KuponaiController#patvirtinimokodas')->name('dashboard');
});

How Can i Call Middleware in this prefix Route?

Hello I am new in laravel framework. can anyone tell me how to apply middleware in this following route?
Route::prefix('Admin')->group(function (){
Route::get('/', 'UserlistController#index');
Route::post('create', 'UserlistController#create')->name('create');
});
There are various to call middleware in the group function.
1st way:- Define middleware after group function.
Route::prefix('Admin')->group(function (){
Route::get('/', 'UserlistController#index');
Route::post('create', 'UserlistController#create')->name('create');
})->middleware('yourmiddlewarename');
2nd way:- to define middleware with a prefix.
Route::middleware(['yourmiddlewarename'])->prefix('Admin')->group(function (){
Route::get('/', 'UserlistController#index');
Route::post('create', 'UserlistController#create')->name('create');
});
You should use Laravel's Route::group() method for proper grouping of routes.
You can group routes like the following:
Route::group(['as' => 'for_named_route','prefix' =>'for_prefixing','namespace' => 'for_namespacing', 'middleware' => 'for_middleware'],function(){
// Your route will go here
);
For your coding purpose your route group should be like the following:
Route::group(['prefix'=>'for_prefixing','middleware'=>'for_middleware'],function(){
// Your route will go here
Route::get('/', 'UserlistController#index');
Route::post('create', 'UserlistController#create')->name('create');
);
You can also pass multiple middleware using an array like:
'middleware'=>['middleware_1','middleware_2']
Route::group(['prefix'=>'admin','middleware'=>['auth']], function(){
Route::post('favorite/{post}/add','FavoriteController#add')->name('post.favorite');
Route::post('review/{id}/add','ReviewController#review')->name('review');
Route::get('file-download/{id}', 'PostController#downloadproject')->name('project.download');
Route::post('file-download/{id}', 'PostController#downloadproject');
});

why i see Call to undefined method Error?

im learning laravel so if im not well as you are accept my apologies...
my problem is when i try to define a new method in web.php i got error!some times phpstorm sets problem on 'Route'word so i can run my blade pages but sometimes it sets problem on 'get','post','group' ,...and i cant run my app
ill show you how i defined my routes
use Illuminate\Routing\Route;
Route::get('/', function () {
return view('welcome');
});
Route::group(['prefix' => 'admin'] ,function (){
Route::get('/users','UsersController#index');
});
after all this my point is making a controller so i got this error to fix so i can move on...
Named groups in laravel
Route::group(['prefix'=>'admins','as'=>'admin.'], function(){
Route::get('users', ['as' => 'user', 'uses' = > 'UsersController#index']);
});
Also make sure you have index method in your UsersController.
FYR :- https://laraveldaily.com/laravel-5-1-names-for-route-groups/

How to remove missingMethod route when using Route::controller() in Laravel 4?

When I use Route::controller() it will automatically generate a route like: GET|HEAD|POST|PUT|PATCH|DELETE resource/{_missing}.
this will make conflict if I have route like resource/{id}/somethingElse.
Sample code
<?php
Route::controller('page', 'PageController');
Route::Group(['prefix' => 'page/{id}/comments'], function() {
Route::get('/', 'CommentController#index');
Route::post('/', 'CommentController#create'); // <-- this will not work sometimes I don't know why
});
The line I highlighted throws NotFoundHttpException with Controller method not found. message.
Is there anyway to remove that route containing {_missing} parameter?

Resources