pH Jhop
pH Jhop

Reputation: 41

Laravel, vue + Inertia insert data

Every time I click the Create New button in my Index.vue of my animal breeds it doesn't redirect to my Create.vue page. I can't find any errors, I spent so much time on troubleshooting but I can't fix it. PS. I'm new in laravel, and please explain to me where did I do wrong.

I tried copy pasting the code of my other insert code, but still doesn't work I'm expecting that it will redirect to my Create.vue page. Here are my codes that is related to my create:

authenticated.php:

use Petcheckr\Common\Ui\Http\Admin\Controllers\AnimalBreeds\CreateController as AnimalBreedsCreateController;


Route::get(
    'config/animal-breeds/create',
    AnimalBreedsCreateController::class,
)->name('config.animal-breeds.create');

CreateController.php:

<?php

declare(strict_types=1);

namespace Petcheckr\Common\Ui\Http\Admin\Controllers\AnimalBreeds;

use Illuminate\Contracts\Support\Responsable;
use Inertia\Inertia;
use Petcheckr\Common\Ui\Http\Admin\Requests\AnimalBreeds\CreateRequest;

class CreateController
{
    public function __invoke(CreateRequest $request): Responsable
    {
        $props = [
            'exampleData' => 'Hello, this is an example!',
            'consoleLogStatement' => 'console.log("This is a console.log statement!");',
        ];

        return Inertia::render(
            'Petcheckr:Configuration:AnimalBreeds/Create',
            compact('props')
        );
    }
}

CreateRequest.php

<?php

declare(strict_types=1);

namespace Petcheckr\Common\Ui\Http\Admin\Requests\AnimalBreeds;

use Illuminate\Foundation\Http\FormRequest;

/**
 * @property-read string $breed_id
 */
class CreateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return !empty($this->user()) && in_array(
            $this->user()->role,
            [
                    'PETCHECKR.ADMIN',
                    'VET_PRACTICE.ADMIN',
                ]
        );
    }
}

portion of my Index.vue:

function createAnimalBreed() {
    router.get(route("petcheckr.config.animal-breeds.create"));
    console.log('create');
}
</script>

<template>
    <TableCard
        :title="$t('petcheckr.configuration.animal_breeds_overview_title')"
        :description="$t('petcheckr.configuration.animal_breeds_overview_description')"
        :actions="tableActions"
        :rows="animalBreed.data"
        :headers="tableHeaders"
        :row-actions="rowActions"
        @view-click="showDetail"
        @create-click="createAnimalBreed"
        actions-type="buttons"
    />
    <Pagination :data="animalBreed" />
    <!-- {{ animalBreed.data }} -->
</template>

Upvotes: 0

Views: 97

Answers (1)

pH Jhop
pH Jhop

Reputation: 41

I finally fixed it, the issue is in my routes from

Route::get(
'config/animal-breeds/create',
AnimalBreedsCreateController::class,
)->name('config.animal-breeds.create');

into this

Route::get(
'/animal-breeds/create',
AnimalBreedsCreateController::class,
)->name('config.animal-breeds.create');

I removed the config

Upvotes: 1

Related Questions