0

I'm new on laravel.

I have functions on my model php. I want to use them in controller and send to view.

This is my example function.

public function select()
    {
        $users = DB::table('garanti')->get();
    }

now I need to use this on controller and view.

In codeigniter I handle it like this:

$data['kategori'] = $this->model->select_s();        
$this->load->view('admin/kategori', $data);
2
  • here you will get the idea about this stackoverflow.com/a/17515014/2567813 Commented Jan 10, 2014 at 12:48
  • Are you having problem with this? Did you tested it? It's not working? Do you have any error messages to show us? Commented Jan 10, 2014 at 12:48

2 Answers 2

2

If you do

class Post extends Eloquent {

    public function select()
    {
       return DB::table('garanti')->get();
    }

}

You can use it in your controller:

$data['kategori'] = with(new Post)->select();        

return View::make('admin/kategori')->with('data', $data);

There are in fact other ways of doing this, but static functions are not really testable, so I wouldn't use them in this case.

Sign up to request clarification or add additional context in comments.

Comments

0

This is a very good LIVE example about using MVC concept in Laravel. in this scenario the Controller is calling a function from the Model class then the Controller handle the view.Take a look.

http://runnable.com/UnFiFHVGrQh1AAA_/mvc-in-laravel-for-php

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.