【发布时间】:2020-08-07 12:55:54
【问题描述】:
传递给 App\Candidate::fileUpload() 的参数 1 必须是 Illuminate\Http\Request 的实例,给定的 Illuminate\Http\UploadedFile 实例,在 C:\xampp\htdocs\Laravel-voting 中调用-system\app\Candidate.php 第 40 行
请我不知道哪里弄错了 this is where I wrote the fill upload function(candidate.php)
The second image is the downward path of the same folder candidate.php
这是我的 user.php 供您查看
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','regno'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function role(){
return $this->belongsTo('App\Role');
}
public function candidate(){
return $this->hasOne('App\Candidate');
}
public function registerVoter($name,$email,$password,$regno){
$newVoter = new User;
$newVoter->name = $name;
$newVoter->email = $email;
$newVoter->password = bcrypt($password);
$newVoter->regno = $regno;
$newVoter->role_id = 2;
$newVoter->save();
}
public static function addCandidate($studentId,$seat,$image){
$user = User::find($studentId);
(new Candidate)->add($user->name,$seat,$user->regno,$user->id,$image,);
}
还有我的 AdminController.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','regno'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function role(){
return $this->belongsTo('App\Role');
}
public function candidate(){
return $this->hasOne('App\Candidate');
}
public function registerVoter($name,$email,$password,$regno){
$newVoter = new User;
$newVoter->name = $name;
$newVoter->email = $email;
$newVoter->password = bcrypt($password);
$newVoter->regno = $regno;
$newVoter->role_id = 2;
$newVoter->save();
}
public static function addCandidate($studentId,$seat,$image){
$user = User::find($studentId);
(new Candidate)->add($user->name,$seat,$user->regno,$user->id,$image,);
}
非常感谢您的努力,在此先感谢。
【问题讨论】:
-
AdminController 和 User 在您的问题中是相同的。复制/粘贴问题。
-
尝试添加App\Http\Requests;上课前或stackoverflow.com/a/45191895/10634638
标签: php laravel file-upload laravel-7