I just installed Mcamara\LaravelLocalization following the documentation but I get an error Call to undefined method Mcamara\LaravelLocalization\Facades\LaravelLocalization::setLocale()
The error comes from the web.php routes file of my package. If I use the same code in my main routes file it works perfect. All other routes of my package work, only those I want to localize don't.
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['web', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath']], function() {
Route::get('/{page}', 'FrontPagesController#index');
});
I found on stackoverflow that this could be because locale in config/app.php is not set but in my case it is set to en.
Can someone help me?
I faced this problem and I just run php artisan config:cache in the terminal and I restarted my editor VS Code
Related
I've been laraveling for 5 months now but I reformatted ubuntu and installed Laravel, this time, it's Laravel 7 instead of Laravel 6. My problem is simple routing giving an error. It's so dead simple you might think I'm a stupid beginner.
In my Web.php
Route::get('/about', function () {
return view('welcome');
});
Route::get('/', function () {
return view('welcome');
});
I also tried using a controller that returns a view and just a simple "string" in Web.php
Route::get('/about', 'UserController#index');
Typing http://localhost/about in the address bar in chrome causes 404 error.
As you can see, there should be no problem returning the same view('welcome'), even if I return a simple return "TEST";, results are the same.
I tried downgrading to Laravel 6 by deleting vendor, changing the Laravel v6 in composer.json and running composer install but still the same, so I think it's not the version.
This has never happened to me before even when I first started with Laravel 6 five months ago and it's a totally fresh project.
enable rewrite_mode of Apache server and restart Apache server it will solve the issue.
Run server with php artisan serve
and then try http://localhost:8000/about hope it will fix your problem
OR
Simply use http://localhost/project/about
I'm using laravel 6 for BE and vuejs for FE. Wtih my local environment ( built on xampp server ), everything was fine. But, when I deployed the app to the server(Lamp server with ubuntu 18.04), I got the following error when I tried to run "php artisan route:list".
Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\Masterdata\CountryController] does not exist.
at /var/www/html/performance.goautobot.chat/public_html/performance/vendor/laravel/framework/src/Illuminate/Container/Container.php:806
try {
$reflector = new ReflectionClass($concrete);
} catch (ReflectionException $e) {
throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
}
And some APIs are not working. The weird part is both "Roles" and "Countries" have exactly the same structure as the following but only apis related to "Roles" are working got "BindingResolutionException" error when I tried with Postman.
Route::group(['middleware' => 'auth:api'], function () {
// Countries
Route::get('masterdata/countries', 'Masterdata\CountryController#index');
// Roles
Route::get('masterdata/roles', 'Masterdata\RoleController#index');
}
I tried to solve it by running the commands like "composer dump-autoload" and "php artisan config:cache" but it didn't fix the problem. Also, tried to remove the project folder and made a new installation and deployment.
Please let me know how to fix the issue. Thank you so much in advance.
I had a similar issue with HomeController, then I checked the routes in the web.php file,
I found it was like the following
Route::get('/', 'HomeController#index');
Then I changed this to the following according to the directory where the Homecontoller resides
Route::get('/', 'App\Http\Controllers\HomeController#index');
after that, it worked correctly.
So Please check your controller directory,
if your controller directory is "App\Http\Controllers\Masterdata\CountryController" then add this in the route. it will be like following
Route::get('/', 'App\Http\Controllers\Masterdata\CountryController');
I tried to explain according to my scenario,
Please let me know if this helps and please pardon me if I have got something wrong
I am upgrading application written in Laravel 4.2 to Laravel 5.2.
I have long namespaces for my controllers and want to shorten them.
For example:
CustomServiceProvider.php
public function register()
{
$this->app->bind('Shortname\Somecontroller', 'Really\Really\Long\Name\Somecontroller');
}
routes.php
$router->get('someroute', ['uses' => 'Shortname\Somecontroller#someFunction']);
was possible inside custom service provider and works in Laravel 4.2 and Larave 5.1. After I've started migrating to Laravel 5.2 it stopped working.
Closest I came to the solution was this issue report: https://github.com/laravel/framework/issues/14920 but it doesn't work either.
This works for example:
routes_alternative.php
$router->get('someroute', ['uses' => 'Really\Really\Long\Name\Somecontroller#someFunction']);
I've tried Really\Really\Long\Name\Somecontroller::class and moving everything to RouteServiceProvider. I've also tried artisan route:clear,artisan cache:clear, artisan dump-autoload, artisan clear-compiled and all sorts of other composer and artisan shenanigans.
All actions result in exception:
ReflectionException in Route.php line 280:
Class Shortname\Somecontroller does not exist
Does someone have similar expiriences and was able to solve it?
Please, help me to find what is going on.
I just set up a basic Laravel project. It's a new fresh Laravel project (5.2.29)
This is route.php
Route::get('/', 'TestController#index');
This is the test controller
class TestController extends Controller
{
public function index()
{
return view('home');
}
}
The home.blade.php is the one that comes with a fresh Laravel installation, the one printing "Laravel 5".
When I add the 'web' middleware, as following
Route::group(['middleware' => ['web']], function () {
Route::get('/', 'TestController#index');
});
I get this error: "Maximum function nesting level of '100' reached, aborting!".
I read some thread about xDebug, so i add this line to xdebug.ini
xdebug.max_nesting_level = 1000
but nothing changed.
Any help? Or any suggestion on what else could I check?
Thank you
Try to remove web middleware, because now it applies automatically to all routes. So, since v5.2.27 you do not need to apply web middleware to avoid errors.
If you installed new application (5.2.27 at the moment of installation), you don't have to use web middleware group because it will be automatically applied, however if you installed version prior to 5.2.27 and then updated to 5.2.27 or later you still need to use it.
So first you need to verify app/Providers/RouteServiceProvider.php if there's web middleware group automatically applied. If yes, you should remove it from routes.php because you might get unexpected behaviour.
If it's not the case, you should verify what Middleware are included into web middleware group because some of them might cause problems
so I started to use Laravel auth and in my Route in web middleware I wrote :
Route::group(['middleware' => ['web']], function () {
Route::auth();
});
and I got this error :
Maximum function nesting level of '100' reached, aborting!
and I tried to use this instead :
Route::auth();
Route::group(['middleware' => ['web']], function () {...});
and then when I wanted to use old function in my form I got this error
Session store not set on request.
can you help me , a tutorial link is also a good idea :)
This is the problem of recursion. So,go into your php.ini configuration file and change the following line:
xdebug.max_nesting_level=100
to something like:
xdebug.max_nesting_level=200
Edit:
If you are using wamp then please comment
zend_extension = "d:/wamp/bin/php/php5.3.8/zend_ext/php_xdebug-2.1.2-5.3-vc9.dll //here wamp is installed in d drive.
in my php.ini file. This extension should be limiting the stack to 100 .
I fixed this problem by adding this line in bootstrap/autoload.php
ini_set('xdebug.max_nesting_level', 200);