I am trying to use the built in registration of Laravel 5 to upload a photo for each user.
I have made the changes that i needed in:
views/auth/register.blade.php
app/User.php
app/services/Registrar.php
And registration works fine.
But when I try to add the file upload logic, my problem is in Registrar.php.
I have added:
use Illuminate\Http\Request;
but in the create method using:
Request::hasFile()
returns an error of can't use as static.
use dependancy injection.
use Illuminate\Http\Request;
class FooController extends Controller {
public function __construct(Request $request)
{
$this->request = $request;
}
public function bar()
{
dd($this->request->hasFile('key'));
}
}
With laravel 5.*
please comment the first line and use the second line.
line 1 :
//use Illuminate\Http\Request;
line 2 :
use Request;
Related
I tried to route with using name .
I already tried to solve with using Composer update , Clear Cache , Generate App key.
But it's showing fatal error .
Error View Message :
(1/1) FatalErrorException
Class 'App\Http\Controllers\Controller' not found
in ClassesController.php line 13
My Route Code Below :
<?php
Route::prefix('Classes')->group(function(){
Route::get('/add','ClassesController#index')->name('AddNewClass');
});
My Controller Code Below :
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ClassesController extends Controller{
public function index()
{
return "Method Access";
}
In this event, I would first ensure that the file containing the class Controller exists in the same directory with the same namespace as the ClassesController, as implied in your code.
If the Controller does not exist, you can either create the class or simply remove the extends Controller and the line use App\Http\Controllers\Controller; from your code.
its worked for me.
usercontroller
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Show the profile for the given user.
*/
/* http://localhost:8080/laravelapps/blog/public/staff */
public function showProfile()
{
return 'new';
}
}
web.php
Route::get('/staff', 'UserController#showProfile');
http://localhost:8080/laravelapps/blog/public/staff
Check whether Controller.php file exists or not in your Controllers folder if not exists download or put from laravel project.
After that run following command php artisan app:name newproject
Make sure in the above line i have updated text 'newproject' that should be first line of your Controller.php file. For example: namespace newproject\Http\Controllers;
I refer to Laravel5.2 LINE Login and try to login my website by Line.
But have some error in my project:
"Driver [line] not supported."
full version CODE
CODE:
1.SocialController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Contracts\Factory as Socialite;
class SocialController extends Controller
{
protected $socialite;
public function __construct(Socialite $socialite)
{
$this->socialite = $socialite;
}
function redirect(){
return $this->socialite->driver('line')->redirect();
}
function callback(){
$user = $this->socialite->driver('line')->user();
var_dump($user);
}
}
Laravel Socialite doesn't support line driver.
If you want that, I think you have three options:
You can do with any HTTP Client (something like guzzle or curl)
You can use PHP SDK (something like line-bot-sdk-php)
You may find some packages (something like socialiteproviders/line)
*** Edited
I'm recently created laravel line package. You can check
https://github.com/naingminkhant/laravel-line
Using Laravel 5.4, I am getting this error on view whenever I call my method it shows on screen
(1/1) FatalThrowableError
Class 'App\Models\Chat\User' not found
Hierarchy of my project :
Controllers
- ChatMessageController
Models
-Chat
-message.php
-User.php
and here's my controller class code :
namespace App\Http\Controllers\Chat;
use App\Http\Controllers\Controller;
use App\Models\Chat\Message;
use App\Models\User;
use Illuminate\Http\Request;
class ChatMessageController extends Controller
{
public function index()
{
$messages = message::with(['user'])->latest()->limit(100)->get();
return response()->json($messages,200);
}
}
In message.php, probably you forgot to add: use App\Models\User;.
So, it is trying to find User in the wrong space.
I´m using Laravel 5.2, and pass to my controller method the $request:
namespace App\Http\Controllers;
use Input, Session, Exception, Request;
class WebController extends Controller {
public function myfunction(Request $request) {
$request->fullUrl();
}
}
But Laravel return me this error:
Call to undefined method Illuminate\Support\Facades\Request::fullUrl()
In the docs for the 5.2 version all is right:
https://laravel.com/docs/5.2/requests
This method fullUrl exits in the Request.php file ...
What is the problem?
You are importing the Request Facade, which is resolving to a Request facade instance when you type hint in your controller's method.
Instead, import the actual Request object:
use Illuminate\Http\Request;
If you must use the facade as well, you can do something like:
use Illuminate\Http\Request;
use Request as RequestFacade;
Just remove Request from use Input, Session, Exception, Request;
and add new line:
use Illuminate\Http\Request;
So final code look like:
namespace App\Http\Controllers;
use Input, Session, Exception;
use Illuminate\Http\Request;
class WebController extends Controller {
public function myfunction(Request $request) {
$request->fullUrl();
}
}
Hope this help you well!
I am working on api part in Laravel 5.2 and trying to fetch the details from Strava. As mentioned in this link http://socialiteproviders.github.io/providers/strava I have done all the steps. In the controller I wrote a function to pass the access token of the user. This is the function which I am using public function
<?php
namespace App\Http\Controllers\Api\v1;
use Illuminate\Http\Request;
use Auth;
use Socialite;
use App\Models\UserTrackerSettings;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class StravaController extends Controller
{
/**
* Get the user by token
*
* #return \Illuminate\Http\Response
*/
public function getTrackerAccess()
{
$trackerDriver = Socialite::driver('strava');
$getToken = UserTrackerSettings::where('tracker_source_name', 'strava')
->where('user_id', Auth::user()->id)->first();
$access_token = $getToken->access_token;
return Socialite::getUserByToken($access_token);
}
}
But when I run the the link in postman I am getting this error
FatalErrorException in StravaController.php line 23:
Call to undefined method SocialiteProviders\Manager\ServiceProvider::driver()
It would be great if someone could help me. Thanks in advance!
Make sure that the actual driver is in there. Afterwards, since I don't see any class inclusions in there, you might need to call that class like this \App\Socialite::driver('strava') or just \Socialite::driver('strava'), I just don't know if that is the full code for your controller or not.