MethodNotAllowedHttpException at calling Model::create in another class service

I'm adding a history register on send petitions Laravel aplication, but when i call the History::create([...]); method, i get the error MethodNotAllowedHttpException. if i comment this method, all works. Follow the service code and History model:

use App\Entities\History;

class PetitionService {

public function newPetition(Request $request, Human $student) {

    //Se o Student estiver na primeira posição da DUPLA
    $doubleStudent = DoubleStudent::all()->where('status', '=', 'active')->where('student_id', '=', $student->id)->first();
    if ($doubleStudent == null) { // se não estiver na primeira posição da DUPLA
        $doubleStudent = DoubleStudent::all()->where('status', '=', 'active')->where('student2_id', '=', $student->id)->first();
    }
    $student_ok = $request->botao == 'ENVIAR'; // 'ENVIAR'(para o professor) ou 'SALVAR'(rascunho)

    $novapeticao = [
        'description' => $request['description'],
        'content' => $request['content'],
        'template_id' => $request['template_id'],
        'doubleStudent_id' => $doubleStudent->id,
        'group_id' => $doubleStudent->group_id,
        'version' => 1,
        'visible' => 'true',
    ];

    if ($student_ok) {
        $novapeticao['student_ok'] = 'true';
    }

    $petition = Petition::create($novapeticao);
    $this->countPetition($doubleStudent);

    $petition->petitionFirst = $petition->id;
    $petition->save();

    History::create([
        'student_id' => $student->id,
        'double_students_id' => $doubleStudent->id,
        'petition_id' => $petition->id,
        'petitionFirst' => $petition->petitionFirst
    ]);

    if ($request['images'] != null) {

        $files = $request->file('images');

        foreach ($files as $file) {

            $fname = $file->getClientOriginalName();

            Photo::create([
                'photo' => Storage::disk(env('STORAGE_TYPE', 'dropbox'))->putFileAs('petition/' . $petition->petitionFirst, $file, $fname),
                'petition_id' => $petition->id,
            ]);
        }
    }

    $mensagem = $student_ok ? 'Petição enviada com sucesso!' : 'Petição salva com sucesso!';
    $request->session()->flash('status', $mensagem);
}

If i remove any fillable item, it show a error about a expected fillable.

namespace App\Entities;

use Illuminate\Database\Eloquent\Model;

class History extends Model {
    protected $fillable = [
        'student_id',
        'doubleStudents_id',
        'petition_id', 
        'petitionFirst'
    ];
}

EDIT: The database table name is "history", i think thats an error on searching the table name to insert the date.

Upvotes: 1

Views: 54

Answers (1)

Was solved, the method was searching a wrong table name. By default, Laravel insert a 's' after the class name to references the table in SQL command. I changed the table name to "records", and with the model called by "Record" and it's worked. Thanks the support!

Upvotes: 0

Related Questions