#Database error

12 messages · Page 1 of 1 (latest)

novel harbor
#

Hey, I got this database error. From what I understand laravel is looking for a main.staff table for no reason. However it doesn't exist because it shouldn't.

Code:

<?php

namespace App\Http\Controllers;

use App\Models\Ticket;
use Inertia\Inertia;
use Inertia\Response;
use Illuminate\Support\Facades\Auth;

class TicketController extends Controller {


    /**
     * Display the create ticket form.
     */
    public function create(): Response
    {
        return Inertia::render('Tickets/Create');
    }

    /**
     * Display the tickets list page
     *
     */
    public function tickets(): Response
    {
        return Inertia::render('Tickets/List');
    }

    /**
     * Display the user's tickets from the database.
     *
     */
    public function index(): Response
    {
        return Inertia::render('Tickets/List', [
            'tickets' => Ticket::where('user_id', Auth::id())->get(),
        ]);
    }

    /**
     * Store a new ticket in the database.
     */

     public function store() {

        $ticket = Ticket::create(
            [
                'title' => request('title'),
                'description' => request('description'),
                'user_id' => Auth::id(),
                'category_id' => request('category_id'),

            ]);
     }
}

Environment
Laravel Version 11.19.0
Php Version 8.3.8
Composer Version 2.7.7
Environment local

#

I might know why now

surreal haven
#

I suspect the problem lies within the Ticket model. If you haven't found the fix, could we see that?

And if it is don't forget to add "Sovled" to the post

novel harbor
#

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;





class Ticket extends Model
{
    use HasFactory;


    protected $fillable = [
        'title',
        'description',
        'user_id',
        'category_id',
        'status_id',
        'staff_id',
    ];
}
novel harbor
surreal haven
#

That seems likely, too now that I know there's a field called staff_id

novel harbor
#

yep. Thats what I figured out. I've now added the staff table + all the other ones - category, statuses. But I've been battling the error as I said

#

Fixed it

#

I dubt that it was the correct way but it works so I don't care

#

Thx. For the help tho