【发布时间】:2019-07-10 09:02:21
【问题描述】:
在我的 laravel 应用程序中,index.blade.php 和 edit.blade.php 不会显示,因为我调用了“destroy”和“update”方法。
老实说,不知道该怎么做。看了其他例子,看不出有什么不同。
index.blade.php(有问题的那一行是表格):
@extends('layouts.app')
@section('content')
<h1>This is your task list</h1>
<ul>
@foreach($tasks as $task)
<li>
<a style ="padding-right:5%" href = "{{route('tasks.edit',$task->id)}}">{{$task->title}} </a>
<form method = 'POST' action ="{{action('TaskController@destroy', @task->id)}}">
@csrf
@method('DELETE')
<div class = "form-group">
<input type = "submit" class= "form-control" name = "submit" value = "Delete">
</div>
</form>
</li>
@endforeach
</ul>
<a href = "{{route('tasks.create')}}">Add a new Todo </a>
@endsection
edit.blade.php(这里也是,问题出在表格行):
@extends('layouts.app')
@section('content')
<h1>Edit Existing Task</h1>
<form method = 'POST' action = "{{action('TaskController@update' , @task->id)}}">
@method('PATCH')
@csrf
<div class = "form-group">
<label for = "title">Task to edit:</label>
<input type = "text" class= "form-control" name = "title" value = "{{$task->title}}">
</div>
<div class = "form-group">
<input type = "submit" class= "form-control" name = "submit" value = "Save">
</div>
</form>
语法错误,意外 '->' (T_OBJECT_OPERATOR),期望 ')'(视图:C:\xampp\htdocs\task\resources\views\tasks\index.blade.php)
【问题讨论】:
-
@task?也许$task?