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.
Related
After 'php artisan make:controller Admin/DashboardController', I included code below (Controllers/Admin/DashboardController).
DashboardController.php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class DashboardController extends Controller
{
//Dashboard
public function dashboard(){
return view('admin.dashboard');
}
}
In web.php:
Route::get(['prefix'=>'admin', 'namespace'=>'Admin', 'middleware'=> ['auth']], function() {
Route::get('/', 'DashboardController#dashboard')->name(admin.index);
});
In views/admin/dashboard.blade.php
#extends('layouts.app)
#section('content')
<h1>Admin test</h1>
#endsection
Whereas the other answers and comments are right admin.index should be 'admin.index', the issue here is because you have a get() route inside another get() route.
If you want to nest routes like this you should use Route::group(...) (not get()):
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('/', 'DashboardController#dashboard')->name('admin.index');
});
Your route name is not a string, so try this:
Route::get('/', 'DashboardController#dashboard')->name('index');
You will again access it as route('admin.index')
I have a REST Controller which I extended with a new action verify(). Now I want to call this action via a named route, but when I open www.foo.bar/verify I get an error:
BadMethodCallException in Controller.php line 273:
Method [verify] does not exist.
When I call the action create instead in the routes.php it works surprisingly.. This is a kind of strange and I have now glue where my error is...
How can I can I call my verify() action with a name route?
app/Http/routes.php
Route::get('/', 'WelcomeController#index');
Route::resource( 'activation', 'ActivationController' );
Route::get( 'verify', [ 'as' => 'verify', 'uses' => 'ActivationController#verify' ]); // throws an error
// Route::get( 'verify', [ 'as' => 'verify', 'uses' => 'ActivationController#create' ]); // this works ?!?
app/Http/Controllers/ActivationController.php
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ActivationController extends Controller {
// ....
public function verfiy( ) {
return "verify";
}
public function create()
{
return "create";
}
// ...
You misspelled the function. :)
public function verfiy( ) {
^^
So I'm learning some basic Laravel stuff as I am new to PHP.
I am following a basic tutorial that is having me print stuff to a file named home.blade.php.
The way I am calling it now is as follows.
Here is my routes.php
Route::get('/', array(
'as' => 'home',
'uses' => 'HomeController#home'
));
Here is my HomeController.php
class HomeController extends Controller {
public function home() {
return View::make('home');
}
}
Here is home.blade.php
{{'Hello.'}}
Before you ask, yes my home.blade.php is inside of my Views folder.
The error print out is as follows
FatalErrorException in HomeController.php line 6:
Class 'App\Http\Controllers\View' not found
in HomeController.php line 6
at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Class 'App\Http\Controllers\View' not found', 'file' => '/Users/ryandushane/Google Drive/Web_WorkSpace/theNeonSurf/app/Http/Controllers/HomeController.php', 'line' => '6')) in compiled.php line 1738
at HandleExceptions->handleShutdown()
Here's the odd part. If I change my routes.php to simply contain
Route::get('/', function()
{
return View::make('home');
});
it functions fine.
Does anyone have an idea of what I could do?
New syntax for Laravel 5
public function home() {
return view('home');
}
For more information you can read it from here http://laravel.com/docs/5.0/views
Try this in your top of the class(controller)
use View;
I bet your controller class has a namespace, yes? Try \View::make('home'); Or you can import it in the top of the file:
<?php
namespace App\Http\Controllers;
use View;
class HomeController extends Controller {
public function home() {
return View::make('home');
}
}
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
}
I'm new to laravel and I'm trying to build a CMS with Laravel to learn it on the go. Now i've got this problem with my routes.
When I visit http://my.app/admin both the views dashboard.index and pages.page are getting loaded. I was under the impression that laravel handles routes in the order they are set in the routes file and if a route gets found everything after that doesn't get executed.
What am i doing wrong here? I'm using Laravel 5.
Routes file:
Route::group(array('prefix' => 'admin'), function()
{
Route::get('/', array(
'as' => 'cms.dashboard',
'uses' => 'DashboardController#index'
));
});
Route::get('/{slug}', array(
'as' => 'pages.page',
'uses' => 'PagesController#page'
));
Controllers:
class DashboardController extends Controller {
public function index()
{
return view('dashboard.index');
}
}
class PagesController extends Controller {
public function page($slug)
{
return view('pages.page');
}
}
Found the problem and it had nothing to do with Laravel.. This was in a javascript file included in the dashboard.index view:
$.get("skin.html", function (data) {
$('body').append(data);
});