Php 无法在laravel中更新
你好,我是新来的,这是我的第一个应用程序 我收到错误:调用未定义的方法stdClass::save() 这是我的模式代码Song.php:Php 无法在laravel中更新,php,laravel,laravel-5,Php,Laravel,Laravel 5,你好,我是新来的,这是我的第一个应用程序 我收到错误:调用未定义的方法stdClass::save() 这是我的模式代码Song.php: <?php namespace App; use Illuminate\Database\Eloquent\Model as Eloquent; class Song extends Eloquent{ protected $table = 'songs'; protected $fillable = ['title']; } 您
<?php namespace App;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Song extends Eloquent{
protected $table = 'songs';
protected $fillable = ['title'];
}
您正在使用DB facade从数据库中获取歌曲-这就是为什么您将结果作为stdClass的对象来获取。改用雄辩模型的方法,你会得到歌曲类的对象
替换
$song_name = DB::table('songs')->whereSlug($slug)->first();
与
如果你想使用save()方法,你需要使用雄辩的notquerybuilder,感谢它的成功。请给我解释一下那首歌::whereSlug($slug)->first();这首歌是我在模型中使用的名字
$song_name = DB::table('songs')->whereSlug($slug)->first();
$song_name = Song::whereSlug($slug)->first();