0

So I have this model "Task" with its controller and views, and when I click edit on a task it keeps giving me Undefined variable.

This is my edit function:

  public function edit(Task $task)
    {
        return view('tasks.edit', [
            compact('task'),
            'project' => Project::all(),
            'client' => Client::all(),
        ]);
    }

This is the view I call in the function above:

 @extends('layouts.app')

@section('content')
    <form method="POST" action="{{route('tasks.update',$task)}}">
        @method('PUT')
    @include('tasks.form')
    </form>
@endsection 

In the form is where it gives me the error. I've realle been trying to see what is wrong but I don't know.

Thanks in advance.

Jesus
  • 117
  • 10
  • Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – miken32 Apr 16 '19 at 19:36
  • 1
    `compact('task')` is returning an array. You're putting it inside another array. – miken32 Apr 16 '19 at 19:37
  • `"task" => compact('task')` - but I never used blade before.... – ArtisticPhoenix Apr 16 '19 at 19:41
  • 1
    @ArtisticPhoenix That actually kind of made it. Thanks for your reply – Jesus Apr 16 '19 at 19:46
  • 3
    `"task" => $task` is how to do it. https://www.php.net/compact – miken32 Apr 16 '19 at 19:48
  • 1
    Sure, as I said I never used it, but I have built things that are similar so I have some idea how it works "under the hood", yea compact is probably not needed even if task was a string you could simply do `['task'=>$task]`, have the same effect. you could array_merge it though :-) What you have is `[['task'=>$task], 'project' => Project::all(), 'client' => Client::all()]` – ArtisticPhoenix Apr 16 '19 at 19:48
  • That's right @miken32 , thank you – Jesus Apr 16 '19 at 19:50

0 Answers0