Route [add.sp] not defined - laravel

i wrote url like that
use App\Http\Controllers\DashController;
Route::get('/admin/special', [DashController::class, 'addSpecializations'])->name('add.sp');
this is controller
public function addSpecializations()
{
return view('dashboard.add-specializations');
}
when i tried to open it i can't even though all route work
after that i wrote this code in view's file
<a href="{{route('add.sp')}}">
so i faced this issue
Route [add.sp] not defined.

In case your routes are cached, run php artisan route:clear. In development, don't cache anything, including views and config.

Related

Route::resource clean /public from URL

I am making a system using the Laravel 5.6
I uploaded to a server that I have and access this externally
You used the software when a route uses resouce, for example::
Route::resource('materiais', 'MaterialController');
Because the routes you create using Route::get, Route::post, Route::patch, etc.., work correctly
For example, if I'm in
http://192.168.0.23/sisobras/public/neworder
and I go to open a new order he goes to the address
http://192.168.0.23/sisobras/public/serviceorder/2/create?
running correctly, a route looks like this:
Route::get('serviceorder/{id}/create', 'ServiceOrderController#create');
but if I'm in
http://192.168.0.23/sisobras/public/materials
and you can register new material the url looks like this:
http://192.168.0.23/materials/create
The view is called on the controller so
public function create()
{
$units = Units::all();
return view('materials/create', compact('units'));
}
and the lack of sisobras/public/ a Not Found error
When used with the php artisan serve works correctly

Blank page for any new route in Laravel

I am using Laravel 5.0 and been developing on this project for months without any problems. I just added a new route with a new method in the controller. But whatever I do, all these new entries in the routes.php file show me a blank page.
In my routes.php:
Route::get('dashboard/product_categories/testing', 'ProductCategoriesController#testing');
In the ProductCategoriesController.php:
public function testing() {
die('Hello world!');
}
This happens to all new entries in the routes.php. No matter what controller its pointed to.
I do not use route:cache so am clueless where this problem stems from
Please note: This is an unchanged project. The httpd server is running as it should and the storage folders have read/write permissions
If you have a resource controller for the dashboard try to add the new routes before the resource.
I totally forgot about this question, but I found the solution: php artisan route:clear
For me, none of the answers helped.
My problem was with two routes matching each other.
A sample of my web.php file is below:
Route::get('user/{user}', 'UserController#show');
Route::get('user/restore, 'UserController#restore');
It took me a while to realise what was happening here.
Despite the fact that $user was typecast in my controller to an instance of User; I just assumed that the string restore would not match that route.
In the end, I realised that the string restore was being passed as a parameter to the route above and was, therefore, failing to match a User model.
To solve this I had to change the route to the following:
Route::get('user/{user}', 'UserController#show')->where('user', '\d+');
Route::get('user/restore, 'UserController#restore');
Now only numbers are matched to that route and the restore route works as expected.
The other solution would be to change the order but I didn't want to do that.
Try clearing the cache:
php artisan cache:clear
Try deleting this before public function methods :
#return \Illuminate\Http\Response

Laravel 5 maintenance mode turn on without artisan

Is there any possibility to turn on and turn off Laravel 5 maintenance without php artisan up and down commands when my website is being hosted ?
What I've done:
Route::get('site/shutdown', function(){
return Artisan::call('down');
});
Route::get('site/live', function(){
return Artisan::call('up');
});
The first route is working fine. But when I call site/live the site still is shuted down. What can cause this problem ?
If your project is already down, you cannot call another function.
What happens after you run php artisan down is that it creates a file named down inside storage/framework. After running php artisan up the file is removed.
You can create the file manually inside storage/framework. It will down your project. When you want to take your project live again, just remove the file.
I think the right answer is missing here..
You could add your route to app/http/middleware/CheckForMaintenanceMode.php
protected $except = [
//here
];
So It never would be off.
when you run artisan down. site is not available so when try to call up, your IP can't access site.
you must call down with your IP exception.
php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16
or add ::1 to local.
to make that in route without command
try to save this command in specific one and call it.
Laravel 8 introduced secret in maintenance mode, in which you can bypass the maintenance mode by providing a secret, then your Artisan::call would work.
You could add your routes to the $except var in CheckForMaintenanceMode middleware to bypass the check. Then your site/live route would work just fine.
In order to make your site live again using an url, you can create a live.php file which you put in laravel's public folder and then visit http://your.domain/live.php .
In the live.php file you need something like this: (check your projects directory structure if you don't use the default public folder!)
<?php
unlink(dirname(__FILE__) . "/../storage/framework/down");
header("Location: your.domain");
die;
just put
Artisan::call('up');
without route function.

Controllers and ajax in laravel 4

I'm new at Laravel and I can't figure how to handle controllers (and ajax).
I have a button in a sidebar, and I want to show a page when it's clicked.
I have a view (which is the page i want to display in ajax) located in views/logs/system.blade.php
and a controller located in controllers/LogsController which has the following code -
class LogsController extends BaseController {
public function getLogs() {
return View::make('logs/system');
}
}
my routes.php has the code -
Route::get('/', 'HomeController#showWelcome'); // Works fine
Route::get('logs', 'LogsController#getLogs');
First things - how can I access the view I'm gettings in getLogs in a URL (localhost/mysite/public/logs doesn't work...)
Second - how can I access it in an ajax call?
I tried
$.get('logs', function(data) {
console.log(data);
});
but it doesn't work either. It gets 500 Internal Server Error....
Help please!
You should be able to go to: localhost/mysite/public/logs
if not, enable mod_rewrite in your apache and in your apache httpd.conf, set:
AllowOverride All
Most probably the server error 500 (in both cases) is caused by the fact that you have a mistake in the View::make() call. To utilize a view in subfolder you have to use the dot notation.
So correct the code
class LogsController extends BaseController {
public function getLogs() {
return View::make('logs.system');
}
}
and you should be good to go, the url should load fine, both in browser and in Ajax.
If you still have problems, check the Laravel Logs (probably path/to/app/storage/logs/...) as well as Apache Error Log (probably /var/log/apache2/error.log). I assume you are using Unix/Linux operating system.
The rewrite module was on.
I solved it by going to localhost/mysite/public/index.php/logs, this is the URL that it expects, maybe something in the .htaccess file is wrong.

Laravel Controller not working

I'm very new to the Laravel framework and am trying to load a simple controller in my browser to slowly get the hang of things.
I have a file that's titled users.php inside of the the laravel/app/controllers/ folder and it looks like this:
class UsersController extends BaseController
{
public $restful = true;
public function action_index()
{
echo 'hi';
}
}
In the routes.php file, I have
Route::get('users', 'UsersController#index');
But, when I go to
http://localhost:8888/laravel/public/users
I'm greeted with a message that says "ReflectionException
Class UsersController does not exist"
I'm not sure if this is because I didn't install the mcrypt extension of PHP. But, when I checked the php.ini file on MAMP, it said that it was enabled. Upon entering
which PHP
in my terminal, it said /usr/bin/php. So, it might not be using the correct version of PHP.
I'm not entirely sure if this is a routes problem or if it's stemming from an absence of a vital PHP extension.
Thanks a bunch!
You need to use the Route::controller method to reference your Controller:
Route::controller('test', 'TestController');
...and rename your file (as Cryode mentions ) to be TestController.php.
Note - if you want to use the filename as test.php, then you will need to use composer to update the autoload settings.
Finally, the format of names for Controller methods changed in Laravel 4, try renaming the method
public function action_index() {}
to be
public function getIndex() {}
the get represents a HTTP GET request... the same applies for post (HTTP POST) and any (GET or POST.. )
I'm not familiar with that part of Laravel's source, so I'm not entirely certain that this is the issue, but your controller file name should match the controller class name, including capitalization.
So users.php should be UsersController.php. Now, when I do this myself on purpose, I get a "No such file or directory" error on an include() call, so that's why I'm not certain that's the sole cause of your problem. But it may be a start.

Resources