lbattaglioli2000
4 months ago

Syntax error in Laravel Controller

Posted 4 months ago by lbattaglioli2000

I've been stuck on this for a good week. I thought it may be due to the fact that my Laravel model is called Class but I'm not quite sure. Here's my controller that is giving me grief:

<?php

namespace App\Http\Controllers;

use App\Class;
use Illuminate\Http\Request;

class ClassController extends Controller
{
   
  public function create()
  {
    return view("admin.new.class");
  }
  
  public function post(Request $request){
        
        // validate the inputted request
        $this->validate($request, [
            // ensures the name is a string, and is filled out (required)
            'name' => 'required|string',
            'hitdice' => 'required|string',
            'hitpoints' => 'required|string',
            'level' => 'required|json',
            'desc' => 'required|string'
        ]);
        
        Class::create([
            'name' => $request->name,
            'hit_dice' => $request->hitdice,
            'hit_points' => $request->hitpoints,
            'level' => $request->level,
            'desc' => $request->desc
        ]);
        
        return redirect('/admin/class/new')->with('success', 'Class created!');
        
  }
}

Please sign in or create an account to participate in this conversation.