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!
Related
Struggling since multiple days to get Notification::assertSentTo() method working in my feature test of reset password emails in a Laravel 5.6 app, yet receiving ongoing failures with following code:
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class UserPasswordResetTest extends TestCase
{
public function test_submit_password_reset_request()
{
$user = factory("App\User")->create();
$this->followingRedirects()
->from(route('password.request'))
->post(route('password.email'), [ "email" => $user->email ]);
Notification::assertSentTo($user, ResetPassword::class);
}
}
I have tried several ideas including to use Illuminate\Support\Testing\Fakes\NotificationFake directly in the use list.
In any attempt the tests keep failing with
Error: Call to undefined method Illuminate\Notifications\Channels\MailChannel::assertSentTo()
Looking forward to any hints helping towards a succesful test.
Regards & take care!
It seems like you are missing a Notification::fake(); For the correct fake notification driver to be used.
Notification::fake();
$this->followingRedirects()
...
I can't use binance api in laravel
I installed Php binance api from composer require "jaggedsoft/php-binance-api #dev" but examples not working in laravel.I had some errors when I tried.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
require '../vendor/autoload.php';
class BinanceController extends Controller
{
public function list()
{
$api = new Binance\API();
$key = "----";
$secret = "---";
$api = new Binance\API($key, $secret);
$price = $api->price("BNBBTC");
return $price;
}
}
When I runned the route I got this error:
Symfony\Component\Debug\Exception\FatalThrowableError Class
'App\Http\Controllers\Binance\API' not found
You're not importing Binance\API correctly. Laravel believes the Binance\Api class is located in the App\Http\Controllers\Binance namespace. Which it is not.
Try $api = new \Binance\API();
Or put it in your use cases.
use Binance\API
I also found an old wrapper which you may be able to import if there hasn't been any changes to Binance since but I highly doubt it. Since your case is specific to Laravel, look for a Binance wrapper for Laravel specifically. Here may contain some useful information on how to use non-laravel packages, with 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
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.
Is there a way to prevent using 'use' for everything. In Laravel 4 I never used 'use' and everything just worked. I'm now finding out I have to include everything, even 'DB' use DB. This is extremely frustrating and time consuming looking all this up.
My question is, is there an easier way to include everything?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Customer;
use DB;
class HomeController extends Controller {
}
?>
Thanks
Not really -- this is the Brave New Namespaced world of PHP 5.3+. Your class file above lives in the App\Http\Controllers namespace, which means when you type something like
$object = new SomeClass;
PHP will assume you mean the class App\Http\Controllers\SomeClass.
You'll either, as you complained about, need to use use, or you'll need to use the full classname (with a leading \ to let PHP know to start from the global namespace) whenever you want to use a class
class HomeController extends Controller {
public function someFunction()
{
$result = \DB::query(...);
$customer = new \App\Models\Customer;
//etc...
}
}
This is question is old but I found you can do this based on information from a tutorial by Tejas Jasani: http://www.theappguruz.com/blog/upgrading-from-laravel-4-2-to-5-in-web
Here are the key steps:
1 - Add the app/Http/Controllers directory to the "autoload" classmap directive of your composer.json file.
"autoload": {
"classmap": [
"database",
"app/Http/Controllers"
],
2 - Remove the namespace from the abstract app/Http/Controllers/Controller.php base class.
3 - In app/Providers/RouteServiceProvider.php file, set the namespace property to null
protected $namespace = null;
4 - Run "composer dump-autoload" from the command line.