I get an issue with the route as follows.
Route [designations.addmore] not defined
I tried to define routes but still i get the same error.Here is my code
View
Add more
Routes.php
Route::get('designations/addmore', ['as' => 'designations.addmore', 'uses' => 'Designations#addmore']);
Controller
<?php
namespace TCG\Voyager\Http\Controllers;
use Illuminate\Http\Request;
use TCG\Voyager\Facades\Voyager;
class Designations extends Controller
{
public function addmore()
{
echo 'hello';
}
}
Please help me.
Change your route like this
Route::get('designations/addmore', 'Designations#addmore')->name('designations.addmore');
and get route in anchor like this
view
remove second param from route because no param in your route.
Related
Below is my web.php content
Route::get('/myRoutes', function () {return view('myRoutes.routeIndex');})->middleware('auth');
Route::get('/myRoutes/{route}', 'routes#show')->middleware('auth');
Route::get('/myRoutes/create', 'routes#create');
Below is my resource controller(route.php)
<?php
namespace App\Http\Controllers;
use App\route;
use Illuminate\Http\Request;
class routes extends Controller
{
public function create()
{
return view('myRoutes.routeCreate');
}
public function show(route $route)
{
return view('myRoutes.routeShow', compact('route'));
}
?>
Now if i visit mydomain.com/myRoutes, it gives me a list of routes available.(working as expected)
If I visit mydomain.com/myRoutes/1, it gives me the record with id=1(working as expected)
Now the issue is if I visit mydomain.com/myRoutes/create, it returns a 404 error that the page not found. If I comment out the following line in web.php
Route::get('/myRoutes/{route}', 'routes#show')->middleware('auth');
then mydomain.com/myRoutes/create works as expected. I think laravel is confused between /myRoutes/{id} and /myRoutes/create. How to fix this?
in your web.php ,add create route before your show route.
Route::get('/myRoutes', function () {return view('myRoutes.routeIndex');})->middleware('auth');
Route::get('/myRoutes/create', 'routes#create');
Route::get('/myRoutes/{route}', 'routes#show')->middleware('auth');
Try putting your create route before your show route in web.php
I am trying to override a route for creating a row. (posting, not viewing)
http://lsapp.dev/admin/cpu-speed/create
In web.php
I modified
Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
Route::post('/cpu-speed',['uses' => 'Admin\Mobiles\CPUSpeedController#store', 'as' => 'store']);
});
Also I created Controller
namespace App\Http\Controllers\Admin\Mobiles;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class CPUSpeedController extends Controller
{
public function store(){
return 'hello';
}
public function create(){
return 'create';
}
}
But it throws the following error:
ErrorException (E_ERROR) Route [voyager.cpu-speed.store] not defined.
(View:
/var/www/html/lsapp/vendor/tcg/voyager/resources/views/bread/edit-add.blade.php)
It appears you are only naming it store here:
Route::post('/cpu-speed',['uses' => 'Admin\Mobiles\CPUSpeedController#store', 'as' => 'store']);
It should probably be:
Route::post('/cpu-speed',['uses' => 'Admin\Mobiles\CPUSpeedController#store', 'as' => 'voyager.cpu-speed.store']);
I'm not entirely sure this will work, since it may be interpreted and descend into the Voyager package, rather than just reading your web.php file, but I believe it will do what you like.
I have Laravel 5.2.45 app.
I have controller structure like this:
App
Http
Controllers
Admin
AdminController.php
inside AdminController.php I have
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
class AdminController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('is.admin');
}
public function index()
{
return view('admin.home');
}
}
I have views folder structure like this:
views
admin
home.blade.php
And inside my routes.php I have
Route::get('/admin/home', 'Admin\AdminController#index');
So I'm trying to get that when I type .../admin/home browser displays home.blade.php inside admin folder.
My routes.php:
Route::auth();
Route::get('/', 'FrontController#index');
Route::get('/home', 'FrontController#index');
Route::get('/add_user', 'FrontController#user');
Route::group(['prefix', 'admin', 'namespace' => 'Admin'], function() {
Route::get('home', 'AdminController#index');
});
The prefix is missing in your route definition. Correct it to look like this:
<?php
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
Route::get('/home', 'AdminController#index');
});
Now, try base_url/admin/home in your browser and it should work.
You can use route groups with the namespace and prefix options.
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
Route::get('home', 'AdminController#index');
});
Here, the prefix allows you to specify the beginning of a URL that should always be in the routes inside the group. So any routes you put inside that group should start with admin.
The namespace lets you specifiy a folder/namespace for the controllers you reference. So all the controllers must be in the App\Http\Controllers\Admin namespace and the app/Http/Controllers/Admin folder.
You need to drop the leading forward slash so it becomes:
Route::get('admin/home', 'Admin\AdminController#index');
I am studying Laravel 5 as my new framework and I am following the video in Laracast and I got some weird error. I am displaying simple view in my controller but all I got is this error:
ModelNotFoundException in Builder.php line 125: No query results for model [App\Article].
Here's a bit of my code:
Route:
Route::get('/', 'WelcomeController#index');
Route::get('home', 'HomeController#index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Route::get('articles', 'ArticlesController#index');
Route::get('articles/{id}', 'ArticlesController#show');
Route::get('articles/create', 'ArticlesController#create'); //returns error page
ArticlesController.php
<?php namespace App\Http\Controllers;
use App\Article;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ArticlesController extends Controller {
public function index() {
$articles = Article::all();
return view('articles.index', compact('articles'));
}
public function show($id) {
$article = Article::findOrFail($id);
return view('articles.show', compact('article'));
}
public function create() {
return 'Hello World'; //display error messages
}
}
So I just confused because when I try to access the create() method the Laravel also read the show() method.
Is this correct? So in the route list the Laravel will read it's routes from top to bottom?
So in my route in order to prevent the error I should put first the route of create before the show?
So it should be like this?
Route::get('articles', 'ArticlesController#index');
Route::get('articles/create', 'ArticlesController#create'); //make it first?
Route::get('articles/{id}', 'ArticlesController#show');
ModelNotFoundException is a db exception fired from the findOrFail method if the model your trying to find don't exist
check this redirect-if-model-doesnt-exists-modelnotfoundexception-doesnt-work-for-me
Because the /create also triggers the show url /{any}
You should do what you said, put the create route over the show route, or delegate that boring job using
Route::resource ('article', 'ArticleController')
Therefore you are getting a modelNotFoundException, because you are looking for an article with id = 'create'
Suppose I had a controller that look like this:
AController.php
<?php namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class AController extends Controller {
public function doThis(){...}
public function doThat(){...}
public function doThing(){...}
}
routes.php
Route::get('/doThis', [
'as' => 'acontroller.dothis', 'uses' => 'AController#doThis'
]);
Route::get('/doThis', [
'as' => 'acontroller.dothat', 'uses' => 'AController#doThat'
]);
Route::get('/doThis', [
'as' => 'acontroller.dothing', 'uses' => 'AController#doThing'
]);
Is there a better way than using Route::get()? I want my route to be automatically ControllerName.methodName and the url to be /methodName without having to explicitly use Route::get()
You're looking for an "implicit controller" (docs here).
If you define your route like:
Route::controller('/', 'AController');
All of the routes underneath the specified prefix (first parameter) will get routed to that controller. Laravel then expects the method names to be defined as a combination of the HTTP verb and the route.
So, your controller would be:
class AController extends Controller {
public function getDoThis(){...} // GET to /doThis
public function postDoThat(){...} // POST to /doThat
public function anyDoThing(){...} // any verb to /doThing
}