I've just installed a Laravel based Application, which seems to work for some of its pages, however many others throw an error and make access to settings or profiles completely impossible. I've seen there are quite a few solutions available online, such as checking writing permissions, etc. however nothing seems to currently work for me, therefore some expert help would be definitely appreciated.
Here my error:
ReflectionException in Container.php line 749:
Class App\Http\Controllers\UserController does not exist
in Container.php line 749
at ReflectionClass->__construct('App\Http\Controllers\UserController') in Container.php line 749
at Container->build('App\Http\Controllers\UserController', array()) in Container.php line 644
at Container->make('App\Http\Controllers\UserController', array()) in Application.php line 709
at Application->make('App\Http\Controllers\UserController') in Route.php line 203
at Route->getController() in Route.php line 316
at Route->controllerMiddleware() in Route.php line 278
at Route->gatherMiddleware() in Router.php line 666
at Router->gatherRouteMiddleware(object(Route)) in Router.php line 646
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
Here is the UserController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
use App\Contact;
use Storage;
use File;
class Usercontroller extends Controller
{
//
private $rules = [
'name' => ['required' , 'min:5'],
'email' => ['required' , 'email'],
'photo'=> ['mimes:jpg,jpeg,png,gif,bmp']
];
private $upload_dir = 'public/uploads' ;
public function __construct()
{
$this->middleware('auth');
$this->upload_dir = base_path() .'/'. $this->upload_dir;
}
private function getRequest(Request $request)
{
$data = $request->all();
if($request->hasFile('photo'))
{
$photo = $request->file('photo');
$filename ="laravel-contact-".time()."-".uniqid()."-".$photo->getClientOriginalName();
Storage::put($filename, File::get($photo->getRealPath()));
$data = $request->all();
$data ['photo'] = $filename;
}
return $data;
}
public function profile()
{
//return view('user.profile', ['user' => User::findOrFail($id)]);
$id = Auth::id();
$user = User::findOrFail($id);
//$this->authorize('modify',$contact);
return view('user.profile',compact('user'));
}
public function show($id)
{
//return view('user.profile', ['user' => User::findOrFail($id)]);
$user = Contact::findOrFail($id);
//$this->authorize('modify',$contact);
return view('user.index',compact('user'));
}
public function update(Request $request)
{
$this->validate($request,$this->rules);
$data = $this->getRequest($request);
$id = Auth::id();
$user = User::findOrFail($id);
$user->update($data);
$oldPhoto = $user->photo;
if ($oldPhoto !== $user->photo){
$this->removePhoto($oldPhoto);
}
return redirect('profile/settings')->with('message','profile updated');
}
public function password()
{
return view('user.password');
}
public function resetPassword(Request $request)
{
$this->validate($request, [
'password' => 'required|confirmed|min:6',
]);
$user = $request->user();
$user->password = bcrypt($request->get('password'));
$user->save();
$id = Auth::id();
$user = User::findOrFail($id);
return view('user.index',compact('user'));
}
public function removePhoto($photo)
{
if (! empty($photo))
{
$path = storage_path('app/public/images/' . $photo);
if (File::exists($path)) {
File::Delete($path);
}
}
}
}
Here my .env file (which I checked for not containing any spaces):
APP_ENV=local
APP_KEY=base64:hcoymkbh8WxkAuetCUOPI3TJ30DrjVzkvNBOigjwopw=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://myurl.com
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=xxxx
DB_USERNAME=xxxx
DB_PASSWORD=xxxx
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
and last but not least, my nginx configuration file for this project:
server {
listen 80;
server_name myurl.com;
root /var/www/html/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Some expert insight would be truly appreciated, thank you very much
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire