Class 'Illuminate\Support\Facade\Mail' not found in laravel 5 - laravel

I get this error message while trying to send email (Class 'Illuminate\Support\Facade\Mail' not found).
in the controller, I have included 'use Illuminate\Support\Facade\Mail;' in the begining of the controller class (PostsController) and in the store function (of the controller), I have this
Mail::send('welcome_email', $data, function ($message) {
$message->from('walegbenga807#gmail.com', 'Coa Blog');
$message->to('nigeriawonderboy#gmail.com')->subject('There is a new post!');
});
return redirect('/')->with('status', 'ticket created');

Try to change the
use Illuminate\Support\Facade\Mail
to
use Illuminate\Support\Facades\Mail;

Since it's a facade, just add this to the top of the class:
use Mail;
Or use full namespace when using the facade:
\Mail::send

Try to use 'use Illuminate\Support\Facades\Mail';
Actually there is no Facade package, but Facades.

Laravel don't know what is "Facade" but try adding s for Facade word.

Try to use
use Illuminate\Support\Facades\Mail;
For more about facades refer:
Facades

Related

Class "App\Http\Controllers\settingsController\Settings" not found

web.php
<?php
use App\Http\Controllers\settingsController\seoController;
use App\Http\Controllers\settingsController\contactController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\generalController\generalRoutes;
use App\Http\Controllers\settingsController\usersController;
Route::controller(generalRoutes::class)->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/getNews', 'getNews');
});
Route::prefix('settings')->group(function () {
Route::controller(contactController::class)->group(function () {
Route::get('/contact', 'index')->name('contactIndex');
Route::post('/contact/update/general', 'generalContactUpdate')->name('generalSContactUpdate');
Route::post('/contact/update/html', 'staticHtmlUpdate')->name('staticHtmlUpdate');
});
});
contactController
<?php
namespace App\Http\Controllers\settingsController;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class contactController extends Controller
{
public function index(){
$data = Settings::find(1);
return view('settings.contact',compact('data'));
}
I wanted create contactController, I had this problem before
Class "App\Http\Controllers\settingsController\contactController" not found
enter image description here
I solve it but now it gives settingsController error
Class "App\Http\Controllers\settingsController\Settings" not found
Please help me))
I want create contactController but it gives settingsController problem
Add this on top of your web.php
Use App\Http\Controllers\settingsController\contactController.php;
Hey Just for clearing your doubts giving you some hint for this basic question.
If you want to use controller you can use it with the help of namespaces like below:
namespace App\Http\Controllers;
And if you want to fix this error Class "App\Http\Controllers\settingsController\Settings" not found
First, you need to specify the modal from where you want the data like this:
use App\Models\Settings;
After that If you want to retrieve data form that modal you can simply do this:
$data = Settings::find($id);
Hope it will help you for basic understanding the usage of controllers and modals in laravel. If you are still struggling with the issue below doc link will surely help you. Keep Learning.
https://laravel.com/docs/9.x/controllers#basic-controllers

Any api routes does not work in laravel project

Any of my laravel project api routes does not work. It returns this
my test route:
Route::get('/test', function() {
return 'test';
});
When I open route in my browser directly (any routes even a test route):
Symfony\Component\ErrorHandler\Error\FatalError
with this error: laravel\framework\src\Illuminate\Auth\SessionGuard.php:29
my SessionGuard file:
<?php
namespace Illuminate\Auth;
use Illuminate\Auth\Events\Attempting;
use Illuminate\Auth\Events\Authenticated;
use Illuminate\Auth\Events\CurrentDeviceLogout;
use Illuminate\Auth\Events\Failed;
use Illuminate\Auth\Events\Login;
use Illuminate\Auth\Events\Logout;
use Illuminate\Auth\Events\OtherDeviceLogout;
use Illuminate\Auth\Events\Validated;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Contracts\Auth\SupportsBasicAuth;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Session\Session;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
class SessionGuard implements StatefulGuard, SupportsBasicAuth // line 29
{
In my artisan console:
PHP Warning: Unexpected character in input: '' (ASCII=1) state=0 in \vendor\laravel\framewor
k\src\Illuminate\Auth\GuardHelpers.php on line 36
My project was working without any problem, and I didnt change anything in my project, but today I have this problem.
Update:
When I create new route, it returns 404 error, cant define new routes, and my old routes still returns old error even when I delete them!

When to use HTTP Request and when to use Illuminate Support Facades Request in laravel?

I have been using laravel so far but sometimes I am so confused about choosing correct Request listed bellow.
use Request;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;
I have created a test method to my corresponding Route & Controller like bellow.
public function test()
{
dd(Request::all());
}
If I choose use Illuminate\Support\Facades\Request; or use Request; it work's fine and get empty array.
But When I choose use Illuminate\Http\Request;
I get error message saying Request::all() should not be called statically. So, it arises two question in my mind.
What's the difference among them ?
When to use Http Request or Illuminate Support Facades Request. Thanks
public function test(Request $request)
{
dd($request->all());
}
Try This

i create new route table on my project, but the class not found

i create a new route table in order to version control and require it on default table
require(__DIR__ . '/Routes/routes_v2.php');
then that my new route
Route::group(['prefix' => 'v2','middleware' => ['web'],'namespace'=>'v2\Home\Service'],function (){
//验证码
Route::post('send', 'ValidateController#sendSMS');
then that's my controller
namespace App\Http\Controllers\v2\Home\Service;
use App\Models\SMS\M3Result;
use Illuminate\Http\Request;
use App\Http\Model\Home\Members;
use App\Http\Model\Home\MembersAuth;
use App\Http\Tools\SMS\SendTemplateSMS;
use App\Http\Model\Home\TempPhone;
use App\Http\Requests;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
use Tymon\JWTAuth\Facades\JWTAuth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class ValidateController extends CommonController
when i run the php artisan route:liston my project
[ReflectionException]
Class App\Http\Controllers\v2\Home\Service\ValidateController does not exis
t
and input the route in url ,they return 500 Internal Server Error
what problem for my route?
My guess, assuming your new routes file is being imported correctly (per my comment, I would advise against creating a "v2" routes file), is that your folder structure does not reflect your namespace. Based on your namespace, Laravel by default will look for the ValidateController in Controllers/v2/Home/Service. Is that where your ValidateController is now?
Also, unless your CommonController class is in the same namespace as the ValidateController, you'll need to import that as well.

How do you change the page name for Paginator?

Current Paginator is using ?page=N, but I want to use something else. How can I change so it's ?sida=N instead?
I've looked at Illuminate\Pagination\Environment and there is a method (setPageName()) there to change it (I assume), but how do you use it?
In the Paginator class there is a method the change the base url (setBaseUrl()) in the Environment class, but there is no method for setting a page name. Do I really need to extend the Paginator class just to be able to change the page name?
Just came across this same issue for 5.1 and you can pass the page name like this:
Post::paginate(1, ['*'], 'new-page-name');
Just like you said you can use the setPageName method:
Paginator::setPageName('sida');
You can place that in app/start/global.php.
Well that didnt work for me in laravel 5 , in laravel 5 you will need to do more extra work by overriding the PaginationServiceProvider because the queryName "page" was hardcoded in there , so first create your new PaginationServiceProvider in /app/providers ,This was mine
<?php
namespace App\Providers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider as ServiceProvider;
class PaginationServiceProvider extends ServiceProvider {
//boot
public function boot()
{
Paginator::currentPageResolver(function()
{
return $this->app['request']->input('p');
});
}//end boot
public function register()
{
//
}
}
Then in your controllers you can do this
$users = User::where("status","=",1)
->paginate(5)
->setPageName("p");

Resources