Laravel NotFoundHttpException on all routes - php

It's laravel version 5.4 and I'm using api.php routes. Following is one of my route in it:
Route::group(['namespace' => 'Api'], function() {
Route::get('auth/test',function(){
return "asd";
});
});
it's giving error on all routes even if I write route in web.php, it's not even loading home page:
http://localhost/bradforduniversityproject/public/
I have run following command too:
php artisan route:clear
nothing is working just giving NotFoundHttpException whatever i write in URL. Any help what could be the reason. thanks!
Following is my api.php file:
Route::group(['namespace' => 'Api'], function() {
Route::get('auth/test2',function(){
return "asd";
});
Route::post('auth/test','Auth\LoginController#test');
Route::post('auth/login','Auth\LoginController#login');
Route::post('auth/register','Auth\LoginController#register');
Route::post('auth/forgotPassword','Auth\LoginController#forgotPassword');
});

Related

"Laravel Error"- Invalid route action: [App\http\Livewire\Logout]

Laravel 8 works fine with laragon locally with the same code, when I upload the same project in the Cpanel and run it shows the error below. I scrutinized the code and could not find the solution. Included the route file below.
The Error:
Invalid route action: [App\http\Livewire\Logout].
Web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\http\Livewire\Logout;
use App\http\Livewire\Login;
use App\http\Livewire\Register;
Route::group(['middleware' => 'auth'], function() {
Route::get('logout', Logout::class)->name('logout');
Route::get('/', function () {
return view('welcome');
});
});
Route::group(['middleware'=>'guest'], function(){
Route::get('login', Login::class)->name('login');
Route::get('register', Register::class)->name('register');
});
Please suggest. Thanks.

Laravel 8: Array to string conversion while trying to run php artisan serve

I have downloaded a project of Laravel and I wanted to run the project by typing php artisan serve but I get this error:
ErrorException
Array to string conversion
But now the problem is, I don't know where this error is coming from and how can I debug!
Here is a capture of it:
So would you just tell me from where I can start debugging and which part of project returns this error (models, controllers, migrations or etc)...
Web.php:
Route::get('/', function () {
$threads = App\Models\Thread::paginate(15);
return view('welcome', compact('threads'));
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::resource('/thread', App\Http\Controllers\ThreadController::class);
Route::resource('/thread/mark-as-solution', [App\Http\Controllers\ThreadController::class, 'markAsSolution'])->name('markAsSolution');
Route::resource('comment', App\Http\Controllers\CommentController::class,['only' => ['update','destroy']]);
Route::post('comment/create/{thread}', [App\Http\Controllers\CommentController::class, 'addThreadComment'])->name('threadcomment.store');
Route::post('reply/create/{comment}', [App\Http\Controllers\CommentController::class, 'addReplyComment'])->name('replycomment.store');
Route::post('comment/like', [App\Http\Controllers\LikeController::class, 'likeIt'])->name('likeIt');
Route::resource('/thread/mark-as-solution', [App\Http\Controllers\ThreadController::class, 'markAsSolution'])->name('markAsSolution');
Here you should edit to get / post / put / patch / delete
Ex:
Route::get('/thread/mark-as-solution', [App\Http\Controllers\ThreadController::class, 'markAsSolution'])->name('markAsSolution');

Laravel 8 default root route not working after route:cache

Getting this error when accessing default '/' route on laravel 8 after doing route:cache
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: HEAD.
Any idea why? all routes except this one is working :D
Route::get('/', function () {
return view('welcome');
});
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
even api.php route is working.
can't find any solution online.
Thank you

NotFoundHttpException while using api_token based authentication in laravel 5.2

I am doing project in laravel 5.2. For authentication, I am using API Token Authentication from Laravel 5.2. I have referred https://gistlog.co/JacobBennett/090369fbab0b31130b51 and my code looks like,
Routes.php
Route::post('login/','UserController#login');
Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () {
Route::get('/', function () {
return "Hi";
});
});
and in UserController.php I did simple login as follows,
public function login(Request $request){
$email = $request->input('email');
$user = DB::table('users')->where('email',$email)->first();
return $user->api_token;
}
I am using postman and first I did login and it returns me the correct api_token from table but when I try to access urls within middleware then it throws an error page as,
Sorry, the page you are looking for could not be found.
1/1
NotFoundHttpException in RouteCollection.php line 161:
I tried,
localhost:8888/ as well as
localhost:8888/api_token=6CnUsIKlmwHXYQNFAuhUTDweUe707gJU2nM2j1Kwjn80nFgmaJHGXuAdN3BX
But still it shows same error page.
Try to change your route / for this code in your Routes.php:
Route::post('login/','UserController#login');
Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () {
Route::get('/', array('as'=>'api_login', 'uses' => 'UserController#api_login'));
});
And in your UserController.php add:
public function api_login(){
return "Hi";
}
I use the Auth class, not an api and if i put the code in Routes.php it didn't work, but if I put the same code inside a Controller and in my Routes.php add the 'uses', it works.
I hope that it works for you too.
Good Luck!
If it helps anyone that googles this issue, I had the same problem and after hours of playing about with it realised it was because I had no api_tokens in my database, once I added it was fine, just weird behaviour that it gives 404 when api_token is not valid.

MethodNotAllowedHttpException Laravel 5.2

Hey so I'm getting this weird error
MethodNotAllowedHttpException
I cannot find a solution anyway on the internet, any advice please?
Here it is:
Route::post('api/avatarDetails/{avId}', 'API\APIController#doAvatarDetails');
Route::get('api/avatarDetails', function() {
return Redirect::to('/')->with('failure', 'You lack the ability to do that young one.');
});
There you go #Alexy
Route::get('/', function() {
return view('welcome');
});
I don't see this route, but you still trying to redirect to it:
Route::get('/', function () {
//
});
If you have one, run php artisan route:clear command which will clear all old route cache.

Categories