dimanche 22 novembre 2015

How can I create function for database activities and call them in controller in Laravel 5.1

I have created a Model names Contest.php and created a function createContest for insert data in database (in contests table):

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Contest extends Model
{   
    public function createContest($request) {
        return $this->insert($request); 
    }

}

And I have a function store in ContestController.php:

public function store(Request $request)
{
    $this->createContest($request);
}

How can I call createContest function of my model from my controller.

I actually want to define all my database queries in my model, and can call them in my controller, I have not much idea about this flow, can some one please help me to understand the flow



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire