【问题标题】:in laravel my controller 3 filed value not passing在 laravel 我的控制器 3 字段值没有通过
【发布时间】:2019-06-19 13:20:40
【问题描述】:

从视图我传递 4 个值 1)name 2)user_filter_id 3)user_staff_id 4)ticket_id 但它不仅传递“ticket_id”其他 3 个值不工作它显示错误

在视图中我正在传递这个值

<ul class="chatonline style-none ">

    @foreach ($ticket_details as $key=>$ticket_detailss)
        <li>
            <h3 style="text-align:center ">TICKET ID<small  class="text-success "><br type="text" id="ticket_id" name="ticket_id" >{{$ticket_detailss->ticket_id }}</small></h3>
        </li>
         <li>
            <h3 style="text-align:center ">SUBJECT<small  class="text-success "><br>{{$ticket_detailss->subject }}</small></h3>
        </li>
          <li>
            <h3 style="text-align:center ">NAME<small  class="text-success "><br type="text" id="names" name="names" >{{$ticket_detailss->name }}</small></h3>
        </li>
           <li>
            <h3 style="text-align:center ">ID<small  class="text-success "><br type="text" id="user_filter_id" name="user_filter_id" >{{$ticket_detailss->user_filter_id }}</small></h3>
        </li>
           <li>
            <h3 style="text-align:center ">STAFF ID<small  class="text-success "><br type="text" id="user_staff_id" name="user_staff_id" >{{$ticket_detailss->user_staff_id }}</small></h3>
        </li>
    @endforeach 

    <li class="p-20"></li>
</ul>

我的控制器

public function manager_send_messageChat(Request $request)

{

  $this->validate($request, [

     'message' => 'required|string|max:255',
     'ticket_id' => 'string|max:255',
     'name' => 'string|max:255',
     'user_filter_id' => 'string|max:255',
     'user_staff_id' => 'string|max:255',

     ]);

       $input['message'] = $request->message;
       $input['manager_staff_id'] = Auth::user()->staff_id;
       $input['manager_filter_id'] = Auth::user()->id;
       $input['manager_name'] = Auth::user()->name;
       $input['reply_by'] = 'staff';
       $input['ticket_id'] = $request->ticket_id;
       $input['user_filter_id'] = $request->user_filter_id;
       $input['user_staff_id'] = $request->user_staff_id;
       $input['name'] = $request->name;      
       User_Ticket_Chat::create($input);


       DB::table('user_tickets')->where('ticket_id', $request->ticket_id)->update(['manager_staff_id' => Auth::user()->staff_id,'status' => 'PENDING']);

    return redirect('/ticket')->with('success',' THIS TICKET ASSIGNED FOR YOU .');

}

我遇到了这个错误

"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_filter_id' cannot be null (SQL: insert into `user_tickets_chats` (`message`, `manager_staff_id`, `manager_filter_id`, `manager_name`, `reply_by`, `ticket_id`, `user_filter_id`, `user_staff_id`, `name`, `updated_at`, `created_at`) values (f, GSL_00006, 1, SUBDOMAIN, staff, 1560777803, , , , 2019-06-19 03:02:06, 2019-06-19 03:02:06))

我的模特

class User_Ticket extends Model
{
protected $table = 'user_tickets';
protected $fillable = [ 'user_filter_id','user_staff_id','ticket_id','subject','message','category','status','manager_staff_id','admin_staff_id','admin_processing','note_for_admin','prioritie','services','name'];
}

【问题讨论】:

  • 我认为您的某些标记不正确。我很惊讶ticket_id 被通过了。
    {{$ticket_detailss->user_staff_id }} 看起来您打算将其作为输入文件而不是 br 标签。 。 ???

标签: laravel laravel-5.7


【解决方案1】:

转到您的 User_Ticket_Chat 模型并使 user_filter_id 可填充

protected $fillable = [
    'user_filter_id'
];

【讨论】:

  • 我已经全部添加了,但是显示同样的问题 protected $table = 'user_tickets'; protected $fillable = ['user_filter_id','user_staff_id','ticket_id','subject','message','category','status','manager_staff_id','admin_staff_id','admin_processing','note_for_admin','优先级','服务','名称'];
  • 转到 cmethod 的顶部并 dd($request-&gt;user_filter_id) 这个检查结果是否得到我认为这不是你的代码错误。未从请求中获取数据
  • 那是错误首先在输入标签中定义测试值以进行测试并尝试转储或死 dd() 并检查你得到的结果
  • 有没有其他方法可以在数据库中存储 foreach 值
【解决方案2】:

首先,您没有在视图中指定任何“输入”。例如 &lt;br type="text" id="user_staff_id" name="user_staff_id" &gt; 应该是 &lt;input type="text" id="user_staff_id" name="user_staff_id" &gt; 和所有输入。

如果您仍然面临此问题,以下指南可能会对您有所帮助。

您需要允许在具有“可填充”的模型中为查询插入的所有字段。例如protected $fillable = [......, 'user_filter_id'];。或者您需要为数据库中的“user_filter_id”字段设置一些默认值。您可以使用迁移来执行此操作。

请通过eloquent,了解有关可填充的更多信息。

【讨论】:

  • Kyadastill 同样的问题
  • 你试过用 {{$ticket_detailss->user_filter_id }} "user_filter_id" name="user_filter_id" value="{{$ticket_detailss->user_filter_id }}">?
  • 请确认您的模型“User_Ticket_Chat”具有足够的可填充属性,因为您正在使用“User_Ticket_Chat”模型插入记录。
猜你喜欢
  • 1970-01-01
  • 2019-06-17
  • 1970-01-01
  • 1970-01-01
  • 2018-09-05
  • 2013-07-25
  • 1970-01-01
  • 1970-01-01
  • 2015-02-08
相关资源
最近更新 更多