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
Related
I have this laravel api hosted on a sharefd hosting siteground, i made some changes like changing the public folder to public html and update the storage filing so i can be able to run the laravel storage link commande bu i encountred this error while trying to access my temporary domain
FULL ERROR NAME
Carbon\Carbon::setLastErrors(): Argument #1 ($lastErrors) must be of type array, bool given, called in /home/customer/www/bassemb5.sg-host.com/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php on line 98
and this is my index.php looks like
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
$app->bind('path.public', fn() => base_path('/public_html'));
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
and this is the line i added and it was working perfectly
$app->bind('path.public', fn() => base_path('/public_html'));
Hi Also managing my old site.
You need to update your composer by using
composer update
And all work fine
We had exactly the same error (same file and line) than OP.
In our research it looks like it got broken after 2.57 (working), for us 2.58 was already failing and broke our pipeline, failing in the "composer install" phase with exactly same error.
As #tomexsans mentions it seems to be fixed in 2.62.1+. We upgraded to the latest available version today (2.64) and worked fine, getting the issue fixed.
--
TL;DR
composer update nesbot/carbon
should do the trick.
Also managing my old site on Siteground, customer contacted told me about 500 error.
When I looked at the Logs nothing is wrong.
When I turned on the app_debug we had the same error.
It does not happen on localhost because I have PHP 8.1 installed.
If you're using PHP 8.2 and this problem appears, you need to update your composer.lock to the latest carbon version
https://github.com/briannesbitt/Carbon/releases/tag/2.62.1
or just pull back your PHP version to 8.1
UPDATE: this error came from Siteground Auto Updating your PHP VERSION to 8.2
I have mine forced to PHP 8.1 yet they still Auto Managed it and upgraded the PHP Version to 8.2 without any notifications or advise
I had this issue a few days again
just type composer update on your terminal that will solve the issue.
Give this a vote afterward.
We used carbon in combination with aporat - store receipt validator.
Unfortunately we couldn't update the nesbot using composer, due hardlocked versions and nesbot being a dependency of another library.
Luckily when comparing the libraries Creator file we saw the hotfix in the latest version, by that time being:
https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Traits/Creator.php
We ended up fixing it with only updating that specific file, since only the setLastErrors() function was updated there.
I truly hope it helps someone.
If you can not change your PHP version to 8.1, you can update this line
File Path
./vendor/nesbot/carbon/src/Carbon/Traits/Creator.php
Line No:
928
Old Line
private static function setLastErrors(array $lastErrors)
New Line
private static function setLastErrors($lastErrors)
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.
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
Fatal Error
Exception class app\http\controllers\controller not found
while I run the command php artisan route:list and other all commands are working correctly.
I have named my project as "Socialite" and give namespace to controller.php as "namespace Socialite\Http\Controllers;". I also auto-dumped my project.
there is no any syntax error in routes/web.php.
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::get('/', 'HomeController#index')->name('start');
Route::get('/signup','HomeController#getSignup')->name('auth.signup');
Route::post('/signup','HomeController#postSignup')->name('auth.signup');
Route::get('/signin','HomeController#getSignin')->name('auth.signin');
Route::post('/signin','HomeController#postSignin')->name('auth.signin');
Auth::routes();
You should use this command to rename an app:
php artisan app:name Socialite
Or change namespace of all classes your app uses manually, for example for Controller.php namespace will be:
namespace Socialite\Http\Controllers;
I have install the Dingo with composer, and change the app.php file. After configure the app.php file, then i have publish vendor that, and get the api.php file.
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers'], function ($api) {
$api->get('users', 'EventsController#index');
});
Then i try php artisan api:routes
This is my result:
+----------------+----------------+------+---------+-----------+------------+----------+
| Host | URI | Name | Action | Protected | Version(s) | Scope(s) |
+----------------+----------------+------+---------+-----------+------------+----------+
| api.kayice.com | GET|HEAD users | | Closure | No | v1 | |
+----------------+----------------+------+---------+-----------+------------+----------+
Then i php artisan serve go to localhost:8000/user
It just show me this Sorry, the page you are looking for could not be found.
Could that anything is might miss for that?
Edited
I have added the provider in the app.php, i think after the vendor publish, the api working, then everythings should working. Or else is the laravel 5.2 problem?
I figure out what is the problem now, i didnt add the prefix in the api.php. Therefore it didnt return me the value.
Edited
But it still does not, most probably the system still no yet support well