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

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?

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.

How to add simple view other than Crud to Laravel Backpack

I'm trying to figure out how to add a simple view (without CRUD) to Laravel Backpack. I've found this article, however I can't make it work.
I have added new controller and view, however I'm getting following error:
Method App\Http\Controllers\Admin\RaportyController::setupRoutes does not exist.
I don't understand the routes, what should I add to make it work?
Thank you
EDIT
I've changed the ::crud to ::get in my routes and I'm getting a different error: App\Http\Controllers\Admin\RaportyParkingoweController is not invokable.
My routes (custom.php) file:
<?php
// --------------------------
// Custom Backpack Routes
// --------------------------
// This route file is loaded automatically by Backpack\Base.
// Routes you generate using Backpack\Generators will be placed here.
Route::group([
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => array_merge(
(array) config('backpack.base.web_middleware', 'web'),
(array) config('backpack.base.middleware_key', 'admin')
),
'namespace' => 'App\Http\Controllers\Admin',
], function () { // custom admin routes
Route::crud('opinie', 'OpinieCrudController');
Route::crud('rezerwacje', 'RezerwacjeCrudController');
Route::crud('uzytkownicy', 'UzytkownicyCrudController');
Route::get('raporty', 'RaportyController');
}); // this should be the absolute last line of this file
It should be a simple fix, point to the method you want in that controller: when you're using Route::get(), make sure to also specify the method you want to point to. It should be Route::get('RaportyParkingoweController#yourMethodName');, not Route::get('RaportyParkingoweController');.

User defined Function works in Route::get() but not Route::group()

I am using laravel 7 and created a function to include all route files includeRouteFiles() in a directory. Im just trying to figure out why this works:
Route::get('/', function () {
includeRouteFiles(__DIR__ . '/someFolder/');
});
and this does not:
Route::group(['namespace' => 'SomeSpace'], function() {
includeRouteFiles(__DIR__ . '/someFolder/');
});
this is located in the web.php file under the routes directory.
I assume the that the code in the ServiceProvider where the functions lives is correct because it works in Route::get().
thank you

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/

Laravel 5.8 error trying to get the 'id' property of non-object

I'm developing an application with Laravel 5.8. In my application, I have a controller that handles backend articles, and it works. I want to display my user-side information in such a way that a user can click on a link and see the detail of an article. For that, I have created a new controller a with a new namespace for the function show my redirection of navigation in different page does not focus that it is en route or URL with Laravel 5.8. Below is the function.
namespace App\Http\Controllers\Cybernaut;
use App\History;
use App\Http\Controllers\Controller;
class HistoryController extends Controller
{
public function show($id)
{
$history = History::find($id);
return view('show_history', compact('history'));
}
}
At the level of the home page I wanted to have my links like these:
<li><a data-hover="history" href="{{route('history.show',$history→id)}}"><span>history</span></a></li>
Error
ErrorException (E_ERROR) Property [id] does not exist on this
collection instance. (View:
C:\laragon\www\venome\resources\views\layouts\partial\header.blade.php)
And here is the route used for the show function.
Route::group(['namespace'=>'cybernaut'], function (){
Route::get('/history/{slug}','HistoryController#show')->name('history.show');
});
Try after modifying the thing I have these at the route level now.
Route::get('/', 'FrontController#index')->name('index');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/admin/dashboard', 'DashboardController#index')->name('admin.dashboard');
Route::group([], function () {
Route::get('/history', 'HistoryController#index')->name('history.index');
Route::get('/history', 'HistoryController#create')->name('history.create');
Route::get('/history/edit', 'HistoryController#update')->name('history.update');
Route::get('/history', 'HistoryController#destroy')->name('history.destroy');
});
Route::group(['namespace' => 'cybernaut'], function () {
Route::get('/history/{history}', [
'as' => 'show',
'uses' => 'HistoryController#show'
]);
});
At the level of the homepage I wanted to put my link like those here now;
#foreach($history as $history)
<li><a data-hover="history" href="{{url('/history/'.$history->id)}}"><span>history</span></a></li>
#endforeach
I have this error now:
Trying to get property 'id' of non-object (View:
C:\laragon\www\venome\resources\views\layouts\partial\header.blade.php)
I want an internaut to be able to navigate between the pages.
You have a conflict of variables on your homepage.
#foreach($history as $history)
should be
#foreach($histories as $history)
where $histories is filled in in your FrontController.
$histories = History::all();
When actually getting your single history object, I agree with Sapnesh's answer that you best doublecheck whether or not the object actually exists.
The error occurs because find() returns NULL when a model is not found.
find($id) takes an id and returns a single model. If no matching model
exist, it returns null.
findOrFail($id) takes an id and returns a single model. If no matching
model exists, it throws an error.
In your show() method,
Change:
$history = History::find($id);
To:
$history = History::findOrFail($id);

Resources