laravel로 자동차 사이트 만들기_DB

sosoeueun·2021년 11월 24일
0

laravel_car

목록 보기
2/3
post-thumbnail

<migration 만들기>
이미지를 DB에 넣을 수 있다? 없다?
=> 있다
있다면 이미지 저장을 위한 데이터 타입은?

blob 타입 (표준)

clob 타입 (책 한권)

-> 일반적으로 잘 안씀

들어갈 수 있는 column 타입
char
varchar
int
number
float
date
timestamp

https://laravel.com/docs/8.x/migrations#available-column-types

compony 테이블을 먼저 만들기로 함
밑에 자동차 정보 테이블에서 컴포니를 참조하는 키가 있기 때문

php artisan make:model Company -m


 Schema::create('companies', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });

라라벨을 기본 not null!

web.php

코드설명
Route::resource('/cars', CarController::class);라우트를 등록해줌
php artisan route:list등록된 라우트 리스트를 볼 수 있음

웹에서 미들웨어 적용 방법

->middleware(['auth'])

: 미들웨어를 적용하면 사용자가 로그인 해야 만 할 수 있다.

컨트롤러에서 미들웨어 적용 방법
: __construct 생성자를 이용해 미들웨어를 지정하는 방법이다

class CarController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('log')->only('index');
        $this->middleware('subscribed')->except('store');
    }
}
옵션설명
->only('index');라우트를 등록해줌
->except('store');store를 빼고 적용

완성 코드

class CarController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth')->except(['index', 'show']);
    }
}

적용된 것은 터미널에서 확인 할 수 있다.

profile
sosoeueun

0개의 댓글