Ad

404 No Errors Displaying In Laravel, How Can I Debug This/fix This Update Route?

enter image description here

I have created a has many relationships with a task model (many tasks to 1 project model) and set up a button to say if a task has been completed or not (1 or 0).

When I click the button to update the database with (as shown in the view) I receive this 404 instead (See pic) instead of the usual error screen which laravel usually throws out, checked the logs no errors there either.

I have attached the code and the network error that comes with the 404 but I don't really know what I am looking for in there if someone can point me in the right direction with 404 error or if there is a mistake in the code below, I would be most grateful!

view

<form method="POST" action="/tasks/{{ $task->id }}">

                @method('PATCH')

                @csrf

                <label for="completed">

                    <input type="checkbox" name="completed" onChange="this.form.submit()">

                    {{ $task->description }}

                </label>

            </form>

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Task;

class ProjectTasksController extends Controller
{
    public function update()
    {
        dd('foo');
    }
}

Route

Route::patch('/tasks/{$task}', '[email protected]');

Migration

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');

            $table->unsignedInteger('project_id');

            $table->string('description');

            $table->boolean('completed')->default(false);

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tasks');
    }
}

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    protected $fillable = [
        'project_id', 'description', 'completed'
    ];

    public function project()
    {
        return $this->belongsTo(Project::class);
    }
}
Ad

Answer

Remove the $ in your route: '/tasks/{$task}'

The route should only contain the variable name as string, since it not yet type hinted into a variable.

Ad
source: stackoverflow.com
Ad