Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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 编辑现有帖子时,在::find()中未定义Lavavel变量_Php_Laravel_Post_Laravel 7 - Fatal编程技术网

Php 编辑现有帖子时,在::find()中未定义Lavavel变量

Php 编辑现有帖子时,在::find()中未定义Lavavel变量,php,laravel,post,laravel-7,Php,Laravel,Post,Laravel 7,我在我的laravel网站上创建了一个编辑现有帖子的功能。然而,当我试图提交给它时,该网站是错误的。它声明了一个未定义的变量:slug,如果你看到我下面的示例,它就没有意义了,因为我的Post日志中的响应显示了对象文件中的变量 public function adminEditPostsPost(Request $request) { $user = Auth::user()->first(); // Log::info($request-&

我在我的laravel网站上创建了一个编辑现有帖子的功能。然而,当我试图提交给它时,该网站是错误的。它声明了一个未定义的变量:slug,如果你看到我下面的示例,它就没有意义了,因为我的Post日志中的响应显示了对象文件中的变量

 public function adminEditPostsPost(Request $request)
     {


        $user = Auth::user()->first();
        // Log::info($request->all());

        $update = false;

       // $token = $request->_token;
        $token = $request->session()->token();

          $postId = $request->input('pxp-submit-comm-id');
          $title = $request->input('pxp-submit-comm-title');
          $overview = $request->input('pxp-submit-comm-overview');
          $post_status = $request->input('pxp-submit-post-status');
          //$images_array = $request->input('pxp-submit-comm-images-array');
          $photo = $request->input('pxp-submit-comm-photo-featured');

          // Log::info($slug);

        $id = $postId;
        $prop_id = 0;

        if ($request->is('admin/*')) {

               $posts = Posts::find($postId);               
               $posts->$title = $title;
               Log::info($posts);
               $posts->$slug = $request->input('pxp-submit-comm-slug');
               $posts->$content = $overview;
               $posts->$featured_url = $photo;
               $posts->$post_status = $post_status;
                

                $posts->save();
         
            }


        $photos = Photos::where('enabled', '<=', '4')->get()->sortByDesc("created_at");
        $posts = Posts::orderBy('created_at', 'DESC')->where('post_status', '<=', '1')->get();

        return view('admin.posts')->with('photos', $photos)->with('posts', $posts);


     }
公共函数adminEditPostsPost(请求$Request)
{
$user=Auth::user()->first();
//日志::信息($request->all());
$update=false;
//$token=$request->\u token;
$token=$request->session()->token();
$postId=$request->input('pxp-submit-comm-id');
$title=$request->input('pxp-submit-comm-title');
$overview=$request->input('pxp-submit-comm-overview');
$post_status=$request->input('pxp-submit-post-status');
//$images_array=$request->input('pxp-submit-comm-images-array');
$photo=$request->input('pxp-submit-comm-photo-featured');
//日志::信息($slug);
$id=$posted;
$prop_id=0;
如果($request->is('admin/*')){
$posts=posts::find($posted);
$posts->$title=$title;
日志::信息(员额);
$posts->$slug=$request->input('pxp-submit-comm-slug');
$posts->$content=$overview;
$posts->$featured\u url=$photo;
$posts->$post\u status=$post\u status;
$posts->save();
}

$photos=photos::where('enabled'),“如果
$title
变量包含
notVariable
,使
$posts->$title
等同于
$posts->notVariable
。因此您只需删除
$posts
键/属性上的
$

改变

$posts->$title = $title;
Log::info($posts);
$posts->$slug = $request->input('pxp-submit-comm-slug');
$posts->$content = $overview;
$posts->$featured_url = $photo;
$posts->$post_status = $post_status;
            


如果
$title
变量包含
notVariable
,使
$posts->$title
等价于
$posts->notVariable
。因此您只需删除
$posts
键/属性上的
$

改变

$posts->$title = $title;
Log::info($posts);
$posts->$slug = $request->input('pxp-submit-comm-slug');
$posts->$content = $overview;
$posts->$featured_url = $photo;
$posts->$post_status = $post_status;
            

PHP允许将变量用作对象键,也允许将变量用作对象键(有关更多解释,请参阅帖子)。您似乎无意中合并了这一原则

在您正在设置的
Log::info()
语句之前

$posts->$title=$title
在PHP中,这实际上是将键设置为
$title
s值,这解释了“现在正在为晚春入住日期建造两座房子”键入对象。对于
$title
,您没有收到未定义变量的错误,因为该变量存在。您收到未定义变量:slug错误,因为您试图使用不存在的变量
$slug
$content
等来设置其他键。您需要更新代码以删除箭头后的
$

$posts->title=$title;
$posts->slug=$request->input('pxp-submit-comm-slug');
$posts->content=$overview;
$posts->featured_url=$photo;
$posts->post\u status=$post\u status;
PHP允许使用变量以及将变量用作对象键(有关详细说明,请参阅帖子)。您似乎无意中加入了这一原则

在您正在设置的
Log::info()
语句之前

$posts->$title=$title
在PHP中,这实际上是将键设置为
$title
s值,这解释了“现在正在为晚春入住日期建造两座房子”键入对象。对于
$title
,您没有收到未定义变量的错误,因为该变量存在。您收到未定义变量:slug错误,因为您试图使用不存在的变量
$slug
$content
等来设置其他键。您需要更新代码以删除箭头后的
$

$posts->title=$title;
$posts->slug=$request->input('pxp-submit-comm-slug');
$posts->content=$overview;
$posts->featured_url=$photo;
$posts->post\u status=$post\u status;

从字面上看,今天我注意到我在对象类型中添加了$。这是我为午夜编码得到的结果哈哈,非常感谢!从字面上看,今天我注意到我在对象类型中添加了$。这是我为午夜编码得到的结果哈哈,非常感谢!
$posts->title = $title;
Log::info($posts);
$posts->slug = $request->input('pxp-submit-comm-slug');
$posts->content = $overview;
$posts->featured_url = $photo;
$posts->post_status = $post_status;