ReflectionException in Route.php line 335: Function () does not exist - php

I'm tryin to get this grid (http://www.mariogallegos.com/tutorials/crud-custom-form) to work in Laravel 5.3.19.
I'm getting the exception:
ReflectionException in Route.php line 335: Function () does not exist
In my web.php i have the followingcode:
Route::group(['middleware' => 'sidebarmenu'], function()
{
Route::get('/home', [
'as' => 'home',
'uses' => 'HomeController#index'
]);
Route::get('/users', [
'as' => 'users',
GridEncoder::encodeRequestedData(new UserRepository(new User()), Request::all())
]);
});

You need to wrap your controller code with a function callback.
Replace
Route::get('/users', [
'as' => 'users',
GridEncoder::encodeRequestedData(new UserRepository(new User()), Request::all());
]);
with
Route::get('/users', function() {
GridEncoder::encodeRequestedData(new UserRepository(new User()), Request::all());
})->name('users');

Related

Laravel saying route not defined but it is?

InvalidArgumentException Route [welcome.begin] not defined.
But it does? Happens when visiting /welcome/begin and I have double checked the file does exist there.
Routes:
<?php
Route::group(['domain' => 'localhost', 'namespace' => 'Frontend'], function () {
Route::group(['middleware' => 'guest', 'namespace' => 'Guest'], function() {
Route::group(['prefix' => 'welcome'], function() {
Route::any('/begin', ['as' => 'frontend.welcome_begin', 'uses' => 'WelcomeController#begin']);
Route::any('/language', ['as' => 'frontend.welcome_language', 'uses' => 'WelcomeController#language']);
Route::any('/final', ['as' => 'frontend.welcome_final', 'uses' => 'WelcomeController#final']);
});
Route::any('/', ['as' => 'login', 'uses' => 'LandingController#redirect']);
Route::get('/login', ['as' => 'frontend.login', 'uses' => 'LoginController#getView']);
Route::post('/login', ['as' => 'frontend.login', 'uses' => 'LoginController#onPost']);
});
Route::group(['middleware' => 'auth', 'namespace' => 'User'], function() {
Route::get('/home', ['as' => 'frontend.home', 'uses' => 'HomeController#getView']);
});
});
WelcomeController:
<?php
namespace App\Http\Controllers\Frontend\Guest;
use App\Http\Controllers\Controller;
use Redirect;
use Illuminate\Http\Request;
class WelcomeController extends Controller
{
public function begin()
{
return route('frontend.welcome.begin');
}
}
View Config:
<?php
return [
'paths' => [
resource_path('views'),
],
'compiled' => realpath(storage_path('framework/views')),
];
There error happens on the "route("frontend.welcome.begin")" line
The route does not exist. Your route is named as frontend.welcome_begin but you are calling frontend.welcome.begin
Your code will need to be: return route('frontend.welcome_begin');
I will suggest, having a brief look at the code, to change your welcome routes to be frontend.welcome.{name} rather than using an underscore, as it will follow the rest of the route names you've defined
First you have check if route name is correct
Open terminal
Go to project cd PATH_TO_PROJECT
write php artisan route:list
Check what is correct route name.

How to redirect after login using entrust package in laravel 5.4

It's not working auto redirect role based after login.
Route::group(['middleware' => 'auth'], function () {
/*Route::get('/', function () {
return view('general');
});*/
Route::resource('users', 'UserController');
Route::get('/admin', [
'as' => 'admin.index',
'middleware' => 'role:admin',
'uses' => function () {
return view('admin.index');
}
]);
Route::resource('roles', 'RolesController');
Route::get('/general', [
'as' => 'general.index',
'middleware' => 'role:general',
'uses' => function () {
return view('general.index');
}
]);
});

Laravel Route Url - Query String - Multi Level

I am trying to achieve url structure like below.
example.com/clients/{client_id} //done
example.com/clients/{client_id}{project_id} // issues
Error is Missing required parameters for [Route: clients.show_project] [URI: clients/{client}/{project_id}].
Route::group(['prefix' => 'clients', 'as' => 'clients.'], function () {
Route::get('/', [
'uses' => 'ClientsController#index',
'as' => 'index',
]);
Route::get('/create', [
'uses' => 'ClientsController#create',
'as' => 'create',
]);
Route::post('/store', [
'uses' => 'ClientsController#store',
'as' => 'store',
]);
Route::group(['prefix' => '{client}', '__rp' => ['menu' => 'clients']], function () {
Route::get('/', [
'uses' => 'ClientsController#show_client',
'as' => 'show',
]);
});
Route::group(['prefix' => '{client}/{project_id}'], function () {
Route::get('/', [
'uses' => 'ClientsController#show_project',
'as' => 'show_project',
]);
});
});
On view
{{ $task->title }}
Controller
public function show_project($client, $project_id)
{
$project_threads = Project_Threads::where('project_id', $project_id)->get();
return $project_threads;
}
The problem is in your view. Your have to pass params in an array in route(). Try this:
{{ $task->title }}

Laravel - root directory routing behaves strangely in a nested route group

I have the following route definition in Laravel 5. When I group the routes in the following way, it seems the route admin.proposals.home will not work if I provide "/" as the get path, and will work if something trailing (like home) is provided:
/**
* Routes for system administrators.
*/
Route::group(['prefix' => 'admin', 'middleware' => 'admin'], function()
{
Route::group(['prefix' => 'people'], function()
{
Route::get('/', ['as' => 'admin.people.home', 'uses' => 'PersonController#index']);
Route::get('/profile/{userName}', ['as' => 'admin.person.profile', 'uses' => 'PersonController#view']);
Route::get('/organization/{id}', ['as' => 'admin.people.organization', 'uses' => 'PersonController#indexByOrganization']);
});
Route::group(['prefix' => 'projects'], function()
{
Route::get('/', ['as' => 'admin.projects.home', 'uses' => 'ProjectController#index']);
Route::get('/{projectId}', ['as' => 'admin.project.view', 'uses' => 'ProjectController#view']);
Route::group(['prefix' => 'proposals'], function()
{
//problematic line below
Route::get('/home', ['as' => 'admin.proposals.home', 'uses' => 'ProposalController#index']);
Route::get('/{proposalId}', ['as' => 'admin.proposal.view', 'uses' => 'ProposalController#view']);
});
});
});
Specifically, if I change the line:
Route::get('/home', ['as' => 'admin.proposals.home',
'uses' => 'ProposalController#index'
]);
To:
Route::get('/', ['as' => 'admin.proposals.home',
'uses' => 'ProposalController#index'
]);
I got an error saying:
Trying to get property of non-object (View: ... \views\admin\projects\view.blade.php)
But, the admin.proposals.home route points to the controllers index() method and has nothing to do with the view.blad.php.
Changing the path back to get('/home') works perfectly.
What is it that I'm missing?
It's a Route position order problem.
Since you have the route for the URI admin/projects/ as admin.project.home, and after that admin/projects/{projectId} it takes precedence over the route admin/projects/proposals/
Laravel takes proposals as the projectId.
Route::group(['prefix' => 'projects'], function()
{
Route::group(['prefix' => 'proposals'], function()
{
//problematic line below
Route::get('/', ['as' => 'admin.proposals.home', 'uses' => 'ProposalController#index']);
Route::get('/{proposalId}', ['as' => 'admin.proposal.view', 'uses' => 'ProposalController#view']);
});
Route::get('/', ['as' => 'admin.projects.home', 'uses' => 'ProjectController#index']);
Route::get('/{projectId}', ['as' => 'admin.project.view', 'uses' => 'ProjectController#view']);
});
Try this order and let me know what you get. But purely it's a route order problem.

Laravel Route group issue

I have been using laravel for a while now, but I stumbled across an error which I have never encountered before. It is probably me overlooking it, but with the route file given below, the route group with the prefix account gives a blank page. When going to /account/anunregisteredroute it does give a httpnotfoundexception
My routes.php file:
http://pastebin.com/EnnGSm10
By adding a / before the parameter you can solve this issue:
Route::get('/{username}', ['as' => 'account-profile', 'uses' => 'AccountController#getProfile']);
This piece of code worked for me:
Route::group(['prefix' => 'account'], function () {
Route::get('/{username}', ['as' => 'account-profile', 'uses' => function($username){
echo $username;
}]);
Route::get('profile', ['as' => 'account-edit-profile', 'uses' => 'AccountController#getUpdate', 'before' => 'auth']);
Route::post('profile', ['as' => 'account-edit-profile', 'uses' => 'AccountController#postUpdate', 'before' => 'auth|csrf']);
Route::group(['before' => 'guest'], function () {
Route::get('create', ['as' => 'account-create', 'uses' => 'AccountController#getCreate']);
Route::get('signin', ['as' => 'account-signin', 'uses' => 'AccountController#getSignin']);
Route::group(['before' => 'csrf'], function() {
Route::post('create', ['as' => 'account-create', 'uses' => 'AccountController#postCreate']);
Route::post('signin', ['as' => 'account-signin', 'uses' => 'AccountController#postSignin']);
});
});
});
I got the expected output.

Categories