Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在laravel中更新_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 无法在laravel中更新

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']; } 您

你好,我是新来的,这是我的第一个应用程序

我收到错误:调用未定义的方法stdClass::save()

这是我的模式代码Song.php:

<?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();