Laravel API routes not found in AWS Elastic Beanstalk - laravel

I am using Laravel 8, and my application is hosted in AWS Elastic Beanstalk. All the routes (routes/web) work fine, but the routes in API (routes/api) show NOT FOUND. The routes API is working ok in the localhost, which is the problem in Elastic beanstalk or EC2 where it is hosted that does not let access to these API routes. Does anyone have any solution? The server's in Apache, pointing out /public.
RouteServiceProvider.php
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* #var string
*/
public const HOME = '/home';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* #var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* #return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* #return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
}

run the commands:
>> php artisan auth:clear-resets
>> php artisan cache:clear
>> php artisan config:clear
>> php artisan event:clear
>> php artisan optimize:clear
>> php artisan route:cache
>> php artisan view:clear
>> php artisan config:clear
>> php artisan view:clear
>> npm run dev
>> php artisan key:generate
>> php artisan optimize

Related

How to clear cached query while i am using array driver in my laravel applications?

I have implemented query cached in my application and my cache driver
is array. But I want to clear all the cached query after certain time.
How can I do so using CLI or in controller ?
php artisan cache:clear
and in controller:
Artisan::call('cache:clear');
You can use this artisan commands for clearing cache from your laravel project:
//---Remove Routes Cache
php artisan route:clear;
php artisan route:cache
//---Flush the application cache
php artisan cache:clear;
//---Remove the configuration cache file
php artisan config:cache;
php artisan config:clear;
//---Clearing View Cache
php artisan view:clear;
php artisan view:cache;
To learn more about cache please visit the following URL:
https://dev.to/kenfai/laravel-artisan-cache-commands-explained-41e1#:~:text=To%20clear%20your%20application%20cache,cache%3Aclear%20Application%20cache%20cleared!
Artisan::call(['cache:clear']);
will run the command php artisan cache:clear. If you want it to be done automatically, you could call that command in the scheduler.
app/Console/Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('cache:clear')->weekly();
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
This will run automatically if you add this entry to your crontab.
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
More on running the scheduler

Generate Artisan command instead of "php artisan serve"

I want to make an alias like
php artisan go
instead of
php artisan serve
I will appreciate any other idea :-) .I also read this link and search a lot but it wasn't so clear and other questions were about making class or .env files and etc.
Thanks in advance
Update
This question is not duplicate of this because it's not contain calling php artisan itself.
Create the command using:
php artisan make:command GoCommand
Add this in the class:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\ConsoleOutput;
class GoCommand extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'go';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$output = new ConsoleOutput;
$output->writeln("Laravel development server started: <http://127.0.0.1:8000>");
Artisan::call('serve');
Artisan::output();
}
}
Use the command:
php artisan go
Visit: http://127.0.0.1:8000/
and see the output in your console.

could not find test routes i made in my laravel request file when i run artisan route:list

i installed Laravel, made new controller and new request.I added a test routes in the request file but whenever i try to access it from the browser via Apache WAMP server it through NotFoundHttpException(1/1)
i tried modifying the Apache httpd.conf file
AllowOverride ALL
Require all granted
i tried php artisan route:clear and route:cache
i tried to access the route through different URLs
public/home
public/index.php/home
not working
however localhost/public loads laravel welcome page just fine
i opened config/app.php file and made sure that the RouteServiceProvider is included in the providers for the app
i opened RouteServiceProvider and the $namespace = 'App\Http\Controllers'
but still when i type php artisan route:list i could not find them
i am trying for a day now can any one help
this is my request file
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class master extends FormRequest
{
Route::get('/home','mastercontroller#index');
Route::get('/lina','mastercontroller#index');
Route::get('/love','mastercontroller#index');
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
//
];
}
}
and this is my controller file
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class mastercontroller extends Controller
{
public function index()
{
return view('index');
}
}
it should load the index view

view [auth.login] not found laravel 5

I had made the routes in routes.php file
Route::controller('auth','Auth\AuthController');
Auth/AuthController.php file is
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use App\Http\Requests\Auth\LoginRequest;
use App\Http\Requests\Auth\RegisterRequest;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* the model instance
* #var User
*/
protected $user;
/**
* The Guard implementation.
*
* #var Authenticator
*/
protected $auth;
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct(Guard $auth, User $user)
{
$this->user = $user;
$this->auth = $auth;
$this->middleware('guest', ['except' => ['getLogout']]);
}
/**
* Show the application registration form.
*
* #return Response
*/
public function getRegister()
{
return view('auth.register');
}
/**
* Handle a registration request for the application.
*
* #param RegisterRequest $request
* #return Response
*/
public function postRegister(RegisterRequest $request)
{
//code for registering a user goes here.
$this->auth->login($this->user);
return redirect('/todo');
}
/**
* Show the application login form.
*
* #return Response
*/
public function getLogin()
{
return view('auth.login');
}
/**
* Handle a login request to the application.
*
* #param LoginRequest $request
* #return Response
*/
public function postLogin(LoginRequest $request)
{
if ($this->auth->attempt($request->only('email', 'password')))
{
return redirect('/todo');
}
return redirect('/login')->withErrors([
'email' => 'The credentials you entered did not match our records. Try again?',
]);
}
/**
* Log the user out of the application.
*
* #return Response
*/
public function getLogout()
{
$this->auth->logout();
return redirect('/');
}
}
When I hit this auth/login it give me the error --
InvalidArgumentException in FileViewFinder.php line 137:
View [auth.login] not found.
Can anyone help me out to resolve this issue.?
Go to
bootstrap/cache
And rename config.php to config.php_
Im pretty sure you have copied from another site and moved also the cache
if you just startet a new project, there aren't auth views out of the box, just as Peter Fox mentioned above.
You will need to enter
php artisan make:auth
to create these views.
This may happened when we are going to do fresh setup. try cleaning first
php artisan view:clear
php artisan config:cache
php artisan route:cache
i got mine to work after modifing the auth.login directroy from /Auth to /auth can be located at laravel/resources/views/Auth
In your file web.php inside the directory routes, delete or comment the line Auth::routes();
if you are in develop mode you can run:
php artisan config:clear
or if you are in product mode you can run bellow code:
php artisan config:cache
notice: when you use second, config clear and cache again and you force to repeat command for other changes.

Artisan: "Command not found"

So I try to add a Command with
php artisan command:make MailSendCommand
The file MailSendCommand.php is created.
I edited it to this:
class MailSendCommand extends Command {
protected $name = 'command:send-mail';
protected $description = 'Send mails to the users.';
public function __construct()
{
parent::__construct();
}
public function fire()
{
$this->info('Befehl wird ausgeführt' );
}
...
In my file start/artisan.php I added
Artisan::add(new MailSendCommand);
but when I enter 'php artisan command:send-mail' it says:
Command "command:send-mail" is not defined.
It just worked on my Home PC (XAMPP) but not on my live server (PHP 5.5.15 (cgi-fcgi))
'php artisan clear:cache' and 'php artisan dump-autoload' did not help.
Go to app/Console/Kernel.php and add the class to the commands variable. It would look something like:
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
Commands\MyCustomCommand::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}
}
Here i added MyCustomCommand as a valid artisan command. Check it is among available commands executing:
php artisan list
It looks as though the problem is related to your setup. You're using PHP CGI instead of CLI to run your commands which will not work.
Ensure that the code is there on your live environment and run your commands on CLI, as these are command line scripts.

Resources