I am getting an errorexception on my view(ErrorException in UrlGenerator.php line 296:). This is my view code:
<?php echo basename($file['name']);?>
For a while it worked, but not don't and I don't know why and how to fix it. I guess I must write something in route.php, but not sure what.....
Route::get('home', ['as' => 'home', function () {
return 'home';
}
]);
Related
I use Laravel with Vue.
I added the following route:
Route::patch('/products/updateOrder', 'Product\ProductController#updateOrder')->name('updateOrder');
I added it in the block:
Route::group([ 'namespace' => 'App\Http\Controllers\Api\BasicData', 'prefix' => 'basicData', 'middleware' => ['role:basicDataAdmin']], function () {
Route::patch('/products/updateOrder', 'Product\ProductController#updateOrder')->name('updateOrder');
Route::get('/products/{product}/productProcesses', 'Product\ProductProcessController#index');
Route::get('/products/{product}/productProcesses/{process}', 'Product\ProductProcessController#show');
Route::post('/products/{product}/productProcesses/{process}', 'Product\ProductProcessController#store');
Route::put('/products/{product}/productProcesses/{process}', 'Product\ProductProcessController#update');
Route::delete('/products/{product}/productProcesses/{process}', 'Product\ProductProcessController#destroy');
Route::resource('/products', 'Product\ProductController')->except(['updateOrder']);
Route::resource('/workplaces', 'Workplace\WorkplaceController');
Route::resource('/partNames', 'PartName\PartNameController');
Route::resource('/processes', 'Process\ProcessController');
});
I get the following error:
"message": "No query results for model [App\\Models\\BasicData\\Product\\Product] updateOrder",
Update order function:
public function updateOrder(Request $request)
{
Product::setNewOrder($request->productIds);
}
I tried to change the order of the routes. Same problem.
When i add an x to the name like this Route::patch('/productsx/updateOrder' it works.
I thought that it's the order of the routes. But it isn't.
Is the only way to solve it to change the name products?
I have an adminmodul, where I can edit or delete some user profiles and i can activate or deactivate an user profile.
Everything works perfect. But suddenly my routes doesnt work anymore. Now I got the error 404 - page not found.
I dont know what the problem is, because I dont change anything in the code.
I think my routes doesnt working. Does anyone know why?
I tried to change my routes.
<?php
Route::get('/', 'AdminController#index');
Route::get('/{id}',[
'as' => 'adminmodul.deactivate',
'uses' => 'AdminController#deactivate'
]);
Route::resource('/adminmodul', 'AdminController');
Route::get('/{id}/edit', 'AdminController#edit')->name('adminmodul.edit');
this is my web.php
i have a AdminController.php where I have methods: index, create(dont use this), edit, update, destroy and deactivate
for example:
public function destroy($id)
{
$user = User::find($id);
$angebot = Angebot::where('firma', $id);
$angebot->delete();
$user->delete();
return redirect('/')->with('success', 'Nutzer wurde erfolgreich gelöscht');
}
public function deactivate($id)
{
$user = User::find($id);
if ($user->verified == 1){
$user->verified = 0;
$user->save();
$angebot = Angebot::where('firma', $id);
$angebot->delete();
return redirect('/')->with('success', 'Nutzer wurde erfolgreich deaktiviert');
}
if($user->verified == 0){
$user->verified = 1;
$user->save();
return redirect('/')->with('success', 'Nutzer wurde erfolgreich aktiviert');
}
}
the index page is working. My views are located in resources/views/adminmodul and then, create.blade.php, edit.blade.php, show.blade.php and index.blade.php
if i hover over the Link, it shows me the right link /1/edit but if I click on this link it goes to /edit
i tried this:
public function test()
{
return 'test';
}
Route::get('/test', 'AdminController#test');
but it doesnt work either and shows me 404
Why do I get 404 page not found?
I think because of wildcards you should try this order to avoid conflict
Route::get('/', 'AdminController#index');
Route::get('/{id}/edit', 'AdminController#edit')->name('adminmodul.edit');
Route::get('/{id}',[
'as' => 'adminmodul.deactivate',
'uses' => 'AdminController#deactivate'
]);
Route::resource('/adminmodul', 'AdminController');
Put your edit route above Route::resource
Route::get('/{id}/edit', 'AdminController#edit')->name('adminmodul.edit');
Route::resource('/adminmodul', 'AdminController');
Note that your new methods have to go above the Route::resource
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/
I have created my own custom function in my RoomsController
public function join($id){
return $id;
}
Then I want to pass variable to it and it says MethodNotAllowedHttpException
And my Form looks like this
{{Form::open(['action'=> ['RoomsController#join', $room->id], 'method' => 'POST' ])}}
{{Form::submit('Join', ['class' => 'btn btn-danger'])}}
{{Form::close()}}
Also have these routes
Route::get('/','PagesController#index');
Route::get('/about', 'PagesController#about');
Route::get('/services', 'PagesController#services');
Route::get('/register', 'PagesController#register');
Route::get('/logout', 'PagesController#logout');
Route::get('/rooms/join', 'RoomsController#join');
Route::resource('posts','PostsController');
Route::resource('rooms','RoomsController');
Auth::routes();
Route::get('/dashboard', 'DashboardController#index');
I have tried in many different ways i dont know why it is not working. All update edit destroy resource functions are working. Thank's for helping :)
You're submitting a POST request but the route is expecting a GET request. If you change your route to Route::post('/rooms/join', 'RoomsController#join'); it should work
change the method to post and put the route below the resource route
Route::resource('rooms','RoomsController');
Route::post('/rooms/join', 'RoomsController#join');
I wrote this code expecting to be redirected to the root url (/ or /home), but instead, it's redirecting to %7Bhome%7D.
Route::get('/{home}', ['as' => 'home', function () {
return view('home');
}])->where('home', '(home)?');
Does anyone know where the problem is?
note: it does support both urls (/ or /home). the problem is just when calling for its name on redirects.
Thanks in advance!
One solution is just to create two routes with the two URLs:
Route::get('/', 'yourController#methodName');
and the other one:
Route::get('/home', 'yourController#methodName');
As you might know, the %7B and %7D are referring to the left and right curly braces { }. I'm not sure why, but it's obviously not leaving out the curly braces when it tries to direct to your route .
It's strange that You cannot redirect using named routes.
Give a try to this:
Route::get('{location}', ['as' => 'home', function ($location = 'home') {
return view($location);
}])->where('location', '(home)?');
or how about this:
Route::any('/', ['as' => 'home', function () {
return view('home');
}]);