Laravel auth won't let me "get" from Database - php

So I've cloned my own laravel project, that works on my main machine, to my test pc and set it up as follows:
Installed XAMPP and set it up.
git clone project to the machine.
Installed composer on the machine.
executed the command composer install.
php artisan key:generate.
I installed Postgres and set up a DB
uncommented Postgres extensions in php.ini
Edited the .env file to connect to the DB
php artisan migrate:fresh.
php artisan db:seed. (New users)
Now when trying to log in, the page just refreshes. I found out that I'm able to read and write to the database when creating a new page that is not protected by the login.
So something with the whole auth situation must be wrong. Did I miss anything when setting the whole project up? Or where the commands executed in the wrong order?
Oh btw. The auth was made with php artisan make:auth
Here is part of my web.php. The whole thing is really big.
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index');
Route::get('/user', 'UsersController#index')->middleware(['auth.admin']);
Route::post('/user', 'UsersController#store')->middleware(['auth.admin']);
Route::get('/user/edit/{id}', 'UsersController#edit')->middleware(['auth.admin']);
Route::post('/user/update/{id}', 'UsersController#update')->middleware(['auth.admin']);
Route::get('/user/delete/{id}', 'UsersController#delete')->middleware(['auth.admin']);
Route::get('/usersearch', 'UsersController#search');
Route::get('/user/paginate/{id}', 'UsersController#paginate')->middleware(['auth.admin']);
Route::get('/order', 'OrderItemController#index');
Route::get('/order/delete/{id}', 'OrderItemController#delete');
Route::get('/order/edit/{id}', 'OrderItemController#edit');
Route::post('/order/update/{id}', 'OrderItemController#update');
Route::post('/order', 'OrderItemController#store');
Route::get('/ordersearch', 'OrderItemController#search');
Route::get('/order/paginate/{id}', 'OrderItemController#paginate');
Route::get('/customer/delete/{id}', 'CustomerController#delete');
Route::get('/customer/edit/{id}', 'CustomerController#edit');
Route::post('/customer/update/{id}', 'CustomerController#update');
Route::get('/customer', 'CustomerController#index');
Route::post('/customer', 'CustomerController#store');
Route::get('/customer/paginate/{id}', 'CustomerController#paginate');

Please check your current laravel version.
php artisan make:auth command is not longer available from Laravel 6.X

Related

Laravel 7.2.5 Unable to prepare route [api/user] for serialization. Uses Closure

I was facing the issue when I do php artisan optimize.
Below is my api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
/* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | is assigned the "api" middleware group. Enjoy building your API! | */
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
I am confuse & don't know what I am missing.
Already tried following options
Delete all cache files
Also tried php artisan cache:clear
Composer update / composer dump-autoload
env file changes CACHE_DRIVER=file,SESSION_DRIVER=database
Thanks in advance .
If you check Laravel's optimize command:
/**
* Execute the console command.
*
* #return void
*/
public function handle()
{
$this->call('config:cache');
$this->call('route:cache');
$this->info('Files cached successfully!');
}
There is a line $this->call('route:cache');
This line is throwing the error.
Laravel is trying to cache the routes. It does not accept Closure while caching the route. That's why moving your code to a controller fixed the issue.

NotFoundHttpException in laravel project

I got this exception for this route: http://localhost:8000/ and other route that I wrote in routes.php file and when I wrote
php artisan route:list
I got this message
Your application doesn't have any routes.
I didn't change anything in my code and it worked successfully.I searched about it but I couldn't find an exact answer why this problem happened.
this is routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
$name = ['saba','safavi'];
return view('welcome'/*,compact('name')*/);
});
Route::get('/sabasafavi', function () {
return "Salam saba safavi";
});
Route::get('/contact-us', function () {
return view("contact-us");
});
\Illuminate\Support\Facades\Route::get('/user/{id}',function ($id){
return "hello user : ".$id;
})/*->where(['id'=>'[0-5]+'])*/;
\Illuminate\Support\Facades\Route::get('/user/{name}/comment/{number}',function ($name,$number){
$comment = "Hello ".$name." this is your comment</br> number : ".$number;
return $comment;
});
/*Route::post('/send',function (){
return "OK information saved successfully";
});*/
First make sure your web.php is being loaded on RouteServiceProvider.php
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
or it might be that your old empty web.php it has been cached since you have cache enabled so do : php artisan route:clear then run php artisan route:list
this problem is because of renaming your Laravel applications.
If you are using an IDE like PHPStorm or sublime do a full search (find in files) (Edit->Find->Find in Path) of laravel5learning across all files in your project directory and all sub-directories and then change it to App
then run php artisan route:list
Please try
php artisan serve
this command and this will give you something like this http://127.0.0.1:8000. So that in localhost you just add this and then your route like -
http://127.0.0.1:8000/
here'/' is your default route i used/
hope will work for you

Laravel 5.2 bind controllers to abstract route

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?

Laravel 5.2, Maximum function nesting level

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

Laravel: Route not found error

I have a newbie question in laravel. I'm trying to query a DB. I have already modified the config to include the necessary credentials for my DB. Now, when i try to query my DB like this:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function()
{
$topPages = DB::table('webmasters') -> get();
return $topPages;
});
I get: Fatal error:
Class 'Route' not found in /.../.../.../dashboard/app/routes.php on
line 13.
I have followed laracast video for accessing a database to the letter, can someone pls tell me what i'm missing or doing wrong here?
Thanks in advance.
maybe the route cache issue run command
php artisan route:cache
Possible Solutions:
Update the app by composer (composer update)
Check for file permission

Categories