Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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中使用ajax保存文件更改_Php_Ajax_Laravel - Fatal编程技术网

Php 在laravel中使用ajax保存文件更改

Php 在laravel中使用ajax保存文件更改,php,ajax,laravel,Php,Ajax,Laravel,我想在不使用Ajax加载编辑页面的情况下更改索引页面中的部分数据。 例如,我的评论具有状态,其中值为0或1以及评论部分。我想从我的索引页更改这些值 我所有的代码只是我的索引方法,在这里我加载我的列表 public function index() { $ratings = Rating::orderby('id', 'desc')->paginate(10); return view('admin.ratings.index', compact('rati

我想在不使用Ajax加载编辑页面的情况下更改索引页面中的部分数据。 例如,我的评论具有
状态
,其中值为
0
1
以及
评论
部分。我想从我的索引页更改这些值

我所有的代码只是我的索引方法,在这里我加载我的列表

public function index()
    {
      $ratings = Rating::orderby('id', 'desc')->paginate(10);
      return view('admin.ratings.index', compact('ratings'));
    }
我需要帮助,使我的索引页面成为一个带有Ajax的表单,以便从那里进行编辑,但不要使用我的
Update
方法,因为我的
edit.blade.php
需要它(可能在我的控制器中添加另一个方法?)


谢谢。

首先,您需要一个更新post状态的控制器。正如我们所讨论的,这完全取决于你想做什么

我的建议是创建一个名为UpdatePostStatusController的新控制器,然后使用update方法,该方法接受post id和状态1或0,并对其进行更新

您的索引文件应该有javascript,每当您像这样更改状态时,它都会被触发

复选框html

<input type="checkbox" data-uuid="{{ $post->id }}" class="update" @if($post->status) checked @endif/>

您的ajax代码在哪里?我们能看一看吗it@usrNotFound正如我提到的,我没有任何Ajax代码,因为我不知道如何使它
我所有的代码都只是我的索引方法,在这里我加载我的列表
Ok,我确定我认为你需要一个更新端点,当你的状态使用Ajax更新时,它会发送post请求,或者,您可以使用store方法使用单独的控制器调用UpdatePostStatusController,该方法只更新帖子的状态并发送ajaxrequest@usrNotFound我有很多控制器我想我会同意你的第一个建议,你介意帮我吗?我当然可以,但如果你想更新你的帖子,第一种方法会发生什么。您将使用什么端点?
 $('.update').change(function() {

  data = {'status' : this.checked }
  post_id =  $(this).data('uuid');

//do your ajax post request here here
}