Idan Brinza
Idan Brinza

Reputation: 21

Syntax error: unexpected '->' in call for destroy method

In my laravel app and index.blade.php and edit.blade.php won't show up becauses of my calls to the "destroy" and "update" methods.

Honestly no idea what to do. Looked at other examples and cant see any differences.

index.blade.php (the problematic line is the one with the form):

@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 (same here, problem lies in the form line):

@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>

syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ')' (View: C:\xampp\htdocs\task\resources\views\tasks\index.blade.php)

Upvotes: 0

Views: 117

Answers (2)

Salman Zafar
Salman Zafar

Reputation: 4045

In both of your blade files you have used @task instead of $task so Change this

<form method = 'POST' action = "{{action('TaskController@update' , @task->id)}}">

To

<form method = 'POST' action = "{{action('TaskController@update' , $task->id)}}">

Upvotes: 1

Abishek
Abishek

Reputation: 11711

The variable being passed on the actions of both the <form> needs to be $task->id instead of @task->id.

Upvotes: 0

Related Questions