0

what is the professional way insert record in database. i am using laravel 5.2. i'm new in laravel.

class students extends Controller
{

    public function index()
    {
         $insertData = array(
        "name"      =>  Input::get("name"),
        "detail"    =>  Input::get("detail"),
        "token_key" =>  Input::get("_token")
    ); 
    return view('student');
    }

    public function fees()
    {
         $record = array(
        "p_name"      =>  Input::get("name"),
        "p_fees" =>  Input::get("fees"),
        "p_detail"  =>  Input::get("detail")
    ); 

    return view('fee');
    }

}

stander able way?

1

3 Answers 3

1

You should use mass assignment. Fill $fillable array inside your model and use this:

Model::create($insertData);
Sign up to request clarification or add additional context in comments.

3 Comments

please explain it how do it corresponding the above given field one method pick you and solve this properly please....................
i have two controoler method insert record here is my model i have two table for insert record in db namespace App\models; use Illuminate\Database\Eloquent\Model; class Designation extends Model { protected $fillable = ['name',detail]; }
other is protected $fillable = ['name','detail',''fees]; table name public static $table = "student" ; others table public static $table = "fees" how to implement fees table for controller method fees .i have no idea how to implement please explain it and how to acces require table from model into controller method
0
  public function store_student(Request $request)
    {
        $student = new Student;
        $student->name = $request->name;
        $student->detail = $request->details
        $student->save();
        return view('student');

    }

public function store_fee(Request $request)
    {
        $fee = new Fee;
        $fee->p_name = $request->name;
        $fee->p_fee = $request->fees;
        $fee->p_detail = $request->details
        $fee->save();
        return view('fee');

    }

Comments

0

I suggest you to read this from Laravel official guide. However you can do it like this:

DB::table('tablename')->insert($insertData);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.