mercredi 24 mai 2017

How can i get result from model in laravel 5

Good day, i'm trying to get the result from my model that called with Mainmodel through my controller, my controller is MainController.

Here is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use app\Mainmodel;

class MainController extends Controller
{


    function index(){
        echo "Kok, direct akses sih?";
    }

    function get_menu(){
         $menu = app\Mainmodel::request_menu();
         dd($menu);
    }

}

Here is my model

   <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Mainmodel extends Model
{
    function request_menu(){
        $menu = DB::table('menu')
                ->orderBy('[order]', 'desc')
                ->get();
         return $menu;
    }
}

my routes

Route::get('menu','MainController@get_menu');

with my script above i get this

FatalErrorException in MainController.php line 17: Class 'App\Http\Controllers\app\Mainmodel' not found

how can i fix this ? thanks in advance.

Note: I'm bit confuse with laravel. I'm using codeigniter before. And i have a simple question. In laravel for request to database should i use model ? or can i just use my controller for my request to database.

sorry for my bad english.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qUu2ui
via IFTTT

Aucun commentaire:

Enregistrer un commentaire