본문 바로가기

php 헛다리/Laravel9 헛다리

라라벨9 컨트롤러에서 모델 호출하는 방법

728x90

 

1번

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\HotModel; // 모델

class HotDefaultController extends Controller
{
    private $HotModel; // 모델

    public function __construct(HotModel $HotModel) // 모델
    {
        $this->HotModel = $HotModel; // 모델
​

 

 

2번

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\HotModel; // 모델

class HotDefaultController extends Controller
{
    private $HotModel; // 모델

    public function __construct()
    {
        $this->HotModel = new HotModel(); // 모델

 

개인적으로 2번째 방법이 맘에드는군

728x90