AuthController.php
namespace App\Http\Controllers;
use App\Mail\VerifyMail;
use App\Models\User;
use App\Models\VerifyUser;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
class AuthController extends Controller
{
//
}
VerifyUser
<?php
namespace App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class VerifyUser extends Model
{
use HasFactory;
protected $guarded = [];
public function user()
{
return $this->belongsTo('App\User', 'user_id');
}
}
The application is made with Laravel 8
do you have any idea what i'm doing wrong ? i get Error Class "App\Models\VerifyUser" not found in AuthController
Related
I have this command line that doesn't work but I tried namespace app\Models\Job; or use app\Models\Job; or namespace App\Models\Job; or use App\Models\Job;.
I have also tried directly adding App\Models\Job to the command line but it didn't seem to work.
namespace App\Http\Controllers;
use app\Models\Job;
use Illuminate\Http\Request;
class JobController extends Controller
{
public function __construct(){
$this->middleware(['employer','verified'],['except'=>array('index','show','apply','allJobs','searchJobs','category')]);
}
public function index(){
$jobs = Job::latest()->limit(5)->where('status',1)->get();
$categories = Category::with('jobs')->paginate(5);
$companies = Company::get()->random(6);
return view('welcome',compact('jobs','
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Job extends Model
{
use HasFactory;
protected $fillable = ['user_id','company_id','title','slug','description','roles','category_id','position','address','type','status','last_date','number_of_vacancy','experience','gender','salary'];
public function getRouteKeyName(){
return 'slug';
}
public function company(){
return $this->belongsTo('App\Company');
}
public function users(){
return $this->belongsToMany(User::class)->withTimeStamps();
}
public function checkApplication(){
return \DB::table('job_user')->where('user_id',auth()->user()->id)->where('job_id',$this->id)->exists();
}
public function favorites(){
return $this->belongsToMany(Job::class,'favourites','job_id','user_id')->withTimeStamps();
}
public function checkSaved(){
return \DB::table('favourites')->where('user_id',auth()->user()->id)->where('job_id',$this->id)->exists();
}
}
You should do this instead:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Job; // change app to App
class JobController extends Controller
{...
I'm trying to force my application to use the write connection when running a select because of race conditions dealing with updating the data and refreshing it. I have confirmed that useWritePdo() function is being called, but I can tell it's not using the write connection because the race condition bug still exists. I don't know how to determine through var dumps whether the write connection is being used.
Here is the code I'm running, followed by the involved models. Note that forcing the write connection works if I call $portfolio->items($useWriteConn), but not $user->portfolios($useWriteConn)->with('items').
return $this->user->portfolios($useWriteConn)->with('items')->find($id);
Model User.php:
namespace App;
use App\Notifications\ResetPassword;
use App\Support\Auth\RetrievesUser;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
/**
* Class User
* #package App
* #property integer $subscription
* #property integer $id
*/
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, UserTrait, Notifiable, HasApiTokens, RetrievesUser
public function portfolios($useWriteConn = false)
{
return ($useWriteConn)
? $this->hasMany(UserPortfolio::class, 'user')->writeConn()
: $this->hasMany(UserPortfolio::class, 'user');
}
}
Model UserPortfolio.php
namespace App;
// use App\UserCustomViews;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
class UserPortfolio extends Model
{
use SoftDeletes;
public function user()
{
return $this->belongsTo(User::class, 'user');
}
public function items($useWriteConn = false, $showClosed = true)
{
$items = $this->hasMany(UserPortfolioItem::class, 'portfolio');
if ($useWriteConn)
$items->writeConn();
if (!$showClosed)
$items->open();
return $items;
}
public function scopeWriteConn($query)
{
return $query->useWritePdo();
}
}
Model UserPortfolioItem.php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
class UserPortfolioItem extends Model
{
public function portfolio()
{
return $this->belongsTo(UserPortfolio::class, 'portfolio');
}
public function scopeWriteConn($query)
{
return $query->useWritePdo();
}
}
For anyone who comes across this later, I found the answer in another thread.
Eloquent pre-loading relationships against DB write connection
Model::onWriteConnection()->with(['relationship'=>function($query){
$query->useWritePdo();
}])->find($id)
I'm new in laravel and i need some help with laravel 5, why is this erro? the error is in Composer class and ComposerServiceProvider
MainComposer class
<?php
namespace App\Htt\Composers;
use Illuminate\Contracts\View\View;
use App\Category;
class MainComposer {
public function compose(View $view){
$view->with('categories', Category::all());
}
}
ComposerServiceProvider.php
<?php
namespace App\Providers;
use View; // its saing class View does not exist
use Illuminate\Support\ServiceProvider;
class ComposerServiceProvider extends ServiceProvider{
public function boot(){
View::composer('*', 'App\Http\Composers\MainComposer');
}
public function register(){
}
}
I have a problem in my controller(AlbumController) , I want to use one of my model(Album) in this controller but I got the error Class 'Album' not found
AlbumController.php :
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
class AlbumController extends BaseController
{
public function getList()
{
$albums = \Album::find(1);
return View::make('index')
->with('albums' , $albums);
}
}
Model : Album.php (App/Models/Album)
<?php
namespace App\Models\Album;
class Album extends Model
{
protected $table = 'albums' ;
protected $fillable = ['name' , 'description' , 'cover_image'] ;
public function Photos()
{
return $this->hasMany('images');
}
}
?>
you are getting this error for namespace mismatch.There is 2 way to solve one is use your namespace in top of class
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Models\Album;
class AlbumController extends BaseController
{
public function getList()
{
$albums = Album::find(1);
return View::make('index')
->with('albums' , $albums);
}
}
another is use full namespace in method
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
class AlbumController extends BaseController
{
public function getList()
{
$albums = \App\Models\Album::find(1);
return View::make('index')
->with('albums' , $albums);
}
}
You not use use Album; in yor controller
Try this
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Album;
class AlbumController extends BaseController
{
public function getList()
{
$albums = Album::find(1);
return View::make('index')
->with('albums' , $albums);
}
}
Error : FatalErrorException in PhotoController.php line 17: Class 'App\Http\Controllers\photo' not found
exception occur on this code -> $a = photo::all();
**PhotoController **
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PhotoController extends Controller {
public function index()
{
$a = photo::all();
print_r($a);
}
**// Photo model**
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Photo extends Model {
protected $table = 'users';
}
Replace in Controller
namespace App\Http\Controllers;
use App\models\Photo;
Replace in Model
namespace App\models;
use Illuminate\Database\Eloquent\Model;