Laravel 4 Resource routing error - php

I have this route :
// work
Route::resource('work', 'WorkController');
Route::get('work/{id}/delete', array('as' => 'admin.work.delete', 'uses' => 'WorkController#confirmDestroy'))
->where('id', '[0-9]+');
and my controller WorkController is residing at App/Controllers/Admin
in the view I call it like this:
<span class="glyphicon glyphicon-book"></span> <br/>Work
and I get this error:
Error Message: Class App\Controllers\Admin\Work does not exist
What is wrong with my code? I have used the same approach for pages, users and menus and it worked.

Can you confirm what is the name of controller file in App\Controllers\Admin?. Also your route should be
// work
Route::group(array('prefix' => 'admin', function()
{
Route::resource('work', 'WorkController');
Route::get('work/{id}/delete', array('as' => 'admin.work.delete', 'uses' => 'WorkController#confirmDestroy'))
->where('id', '[0-9]+');
});

Related

Laravel 5.6 Route Group

My controllers which are HomeController and BlogController in Admin folder. My views like:
/admin
index.blade.php
/blog
index.blade.php
I want to call /admin0admin url to /resources/views/admin/index.blade.php.
I want to call /admin0admin/blog url to /resources/views/admin/blog/index.blade.php
Here how i call in view:
<a href="{{ route('admin0admin.blog') }}" class="br-menu-link">
And my routes like:
Route::group(['namespace' => 'Admin', 'prefix' => 'admin0admin'], function () {
Route::get('/', 'HomeController#index')->name('index');
Route::group(['prefix' => 'blog'], function () {
Route::get('/', 'BlogController#index')->name('index');
});
});
And my BlogController index method:
return view('admin.blog.index');
I got an 404 not found error.
Route [admin0admin.blog] not defined
Laravel Version is : 5.6.*
You need to name the route admin0admin.blog, not index. prefix does not affect names of routes, so you need to write it out.

Controller changes does not reflect

I have a problem. I tried to change the controller but when I open the route it doesn't reflect with the latest controller? Any idea?
Controller
public function indexApplication(){
return "testing";
}
Api.php
Route::group(['prefix' => '/claim'], function(){
Route::get('/test', ['as' => 'claim.test', 'uses' => 'ClaimController#indexApplication']);
}
Response from rest client

Laravel route Resource breaks another route

When I use my route like this, the test route is working fine.
Route:-
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController#myFavorite');
Route::get('user/test','UserController#test'); // is working
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'USerController#planed']);
.
.
.
.
But when I want to use it like following, it shows a blank page :
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController#myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController#planed']);
Route::get('user/test','UserController#test'); // is not working
.
.
.
.
What is my mistake?
Because the call to test is intercepted by
Route::resource('user', 'UserController');
because if you check the routes in the console with
$> php artisan route:list
you'll see it includes
GET|HEAD | user/{user}
and then your first route
Route::get('user/test','UserController#test'); // is not working
is never reached. Try to put it BEFORE the other line.
I thing the issue in naming the route check This
Try like this
Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController#myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed','UserController#planed'])->name('user.planed');
Route::get('user/test','UserController#test'); // is not working
Just replace
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController#planed']);
With
Route::get('user/planed','UserController#planed'])->name('user.planed');

Laravel: how to use /admin

I want to create pages for admin and I want to use dashboard in localhost:8000/admin url...but the page is showing a display Not Found Error.
Please tell me what should I do to resolve this
You need somethig like this in your /app/Http/routes.php
Route::group(['prefix' =>'admin', 'namespace' => 'admin', 'middleware' => 'auth'], function() {
Route::get('/', 'AdminController#index');
// .....
});

Accessing route for form submit in Laravel

i am trying to access one route like pages.trashmultiple this in my view. But its throwing error of Route [pages.trashmultiple] not defined.. Here is how my view looks like:
{!!Form::open([
'method' => 'put',
'route' => 'pages.trashmultiple'
])!!}
<th class="table-checkbox">
<input type="checkbox" class="group-checkable" data-set="#sample_3 .checkboxes"/>
</th>
{!!Form::close()!!}
This is how my controller looks like:
public function trashmultiple(Request $request){
//return "trash multiple page";
return Input::all();
}
And this is how my routes look like:
Route::group(['middleware' => ['web']], function () {
Route::get('pages/trash', 'PagesController#trashpage');
Route::get('pages/movetotrash/{id}', 'PagesController#movetotrash');
Route::get('pages/restore/{id}', 'PagesController#restore');
Route::get('pages/trashmultiple', 'PagesController#trashmultiple'); //this is not working
Route::resource('pages', 'PagesController');
});
When i load my url http://localhost:8888/laravelCRM/public/pages it shows me this below error:
ErrorException in UrlGenerator.php line 307:
Route [pages.trashmultiple] not defined. (View: /Applications/MAMP/htdocs/laravelCRM/resources/views/pages/pages.blade.php)
I want to know why i am unable to access the pages.trashmultiple when i have already defined it.
Is there any way i can make it accessible through pages.trashmultiple?
Thank you! (in advance)
chnage your route to like this:
Route::get('pages/trashmultiple', 'PagesController#trashmultiple');
To
Route::get('pages/trashmultiple', [
'as' => 'pages.trashmultiple', 'uses' => 'PagesController#trashmultiple'
]);
Change your route so that it becomes:
Route::get('pages/trashmultiple',
['as'=>'pages.trashmultiple',
'uses'=>'PagesController#trashmultiple']);

Categories