Where to locate database logic in laravel?

Viewed 1142

I am currently new to laravel and I am trying to wrap my head around code structure with laravel. The reason for learning laravel is to grow my knowledge on creating good code in addition to creating an easily to manage application. For this reason, It is important to me that I am building my application to an accepted standard.

I have read several articles but am still not exactly sure where to organize things.

As of now, my application structure looks as so:

app/
    Console
    Exceptions
    Http
       Controllers
           Auth
           Message
           Settings
       Middleware
    Providers
    Traits
        Message
        Settings

One of my controller looks like something like this:

<?php

namespace App\Http\Controllers\Message;

use DB;
use Auth;
use Request;
use App\Http\Controllers\Controller;

class TypeController extends Controller
{
    public function __construct () {
        $this->middleware('auth');
        $this->middleware('access');
    }

    public function type () {
        $this->adjustTypingStatus(1);
    }

    public function untype () {
        $this->adjustTypingStatus(0);
    }

    protected function adjustTypingStatus ($level) {
        DB::table('user_lobby_info')
            ->where('userid', Auth::User()->id)
            ->where('lobby', Request::get('lobbyid'))
            ->update([ 'typing' => $level ]);
    }
}

?>

The Question

What is a better way to separate controllers into smaller, more manageable pieces? Should I put the database logic into the model and just call the model's method?

2 Answers
Related