$model = Model::find(1); 에서 find는 primary key를 가지고 찾을 때 쓰는 게 아닌가요? 레코드 하나만 가지고 올 때 쓰는 걸로 알고 있었는데 블레이드뷰에서 {{$model->someFunction()}} 이런식으로 function을 호출 한다는게 이해가 안갑니다.
그리고 View::make라는 구문은 라우팅 할때 쓰는 건가요? 'view'라는 모델을 만들때 모델도 같이 던지는거 같은데 컨트롤러에서 부로 리턴 시킬때 모델도 같이 넘겨 주면 안되나요?
다음 내용은 구글링에서 찾은 답변중 하나 입니다
Related to the question in your answer:
You have multiple options to achieve this that are way better:
Let's assume you have a model which you pass to the view:
Now in your Model you could have a function:
In your view you could call that function directly:
This is nice if you want to do something with the model (the dataset).
If not you can still make a static function in the model:
And then:
Hope it helps.
답변중에
$model = Model::find(1); 에서 find는 primary key를 가지고 찾을 때 쓰는 게 아닌가요? 레코드 하나만 가지고 올 때 쓰는 걸로 알고 있었는데 블레이드뷰에서 {{$model->someFunction()}} 이런식으로 function을 호출 한다는게 이해가 안갑니다.
그리고 View::make라는 구문은 라우팅 할때 쓰는 건가요?
'view'라는 모델을 만들때 모델도 같이 던지는거 같은데 컨트롤러에서 부로 리턴 시킬때 모델도 같이 넘겨 주면 안되나요?
메뉴얼 뒤져 봐도 어디에 있는지도 모르겠고, 검색기능도 없고...
$model = Model::find(1);
View::make('view')->withModel($model);
요 두줄의 소스코드만 좀 가르쳐 주십시오.
http://stackoverflow.com/questions/29007639/laravel-5-call-a-model-function-in-a-blade-view
구글링했던 답변 페이지 url 입니다.