我的 Controller 中有以下方法:
public function store(Request $request){
$data = session()->get('dmca');
// return $data;
$notice = Notice::open($date);
$notice->useTemplate($request->input('template'));
$notice->save();
return Notice::first();
}
当 Controller 运行时,我收到以下错误:
现在我有以下模态类:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Notice extends Model {
protected $fillable = [
'provider_id',
'infringing_title',
'infringing_link',
'original_link',
'original_description',
'template',
'content_removed'
];
public static function open(array $attributes) {
return new static($attributes);
}
public function useTemplate($template) {
$this->template = $template;
}
}
现在为什么我在 laravel class not find 中收到此错误,即使我定义了这个类??
最佳答案
只需在 Controller 类顶部使用 use
关键字即可。
<?php
namespace App\Http\Controllers;
use App\Notice; // <------------------ use here
use App\Http\Controllers\Controller;
class UserController extends Controller
{
public function store(Request $request)
{
$data = session()->get('dmca');
// return $data;
$notice = Notice::open($date);
$notice->useTemplate($request->input('template'));
$notice->save();
return Notice::first();
}
}
The
use
keyword helps php to recognize the classNotice
within a certain namespace
希望这有帮助!
关于php - `Class not found` 错误,即使类被定义为模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41125147/