는 일반적으로 리디렉션 및 데이터가 성공적으로 삽입됩니다리디렉션해야 왜 모델 laravel에 빈 페이지가 표시됩니까? 나는 다음과 같은 코드가 작동하는 이유를 묻고 싶습니다
CategoriesController :
public function store()
{
$data = Input::all();
$category = new Term;
if($category->saveCategory($data)){
return Redirect::route('admin_posts_categories')->withSuccess('Category successfully added.');
}else{
return Redirect::route('admin_posts_categories')->withError('Failed to add category. #ErrorCode : 13');
}
}
용어 모델 :
public function saveCategory($data){
$this->name = $data['name'];
$this->slug = $data['slug'];
if($this->save()){
$category_taxo = new TermTaxonomy;
$category_taxo->term_id = $this->lastCategoryId();
$category_taxo->taxonomy = 'category';
$category_taxo->description = $data['description'];
if($category_taxo->save()){
return true;
}else{
return false;
}
}else{
return "#Error Code : 4";
}
}
을 다음과 같은 데이터 만 삽입 하나 빈 페이지가 표시되고 리디렉션되지 않습니다.
CategoriesController :
가public function store()
{
$data = Input::all();
$category = new Term;
$category->saveCategory($data);
}
또한 용어 모델
public function saveCategory($data){
$this->name = $data['name'];
$this->slug = $data['slug'];
if($this->save()){
$category_taxo = new TermTaxonomy;
$category_taxo->term_id = $this->lastCategoryId();
$category_taxo->taxonomy = 'category';
$category_taxo->description = $data['description'];
if($category_taxo->save()){
return redirect::route('admin_posts_categories')->withSuccess('Category successfully added.');
}else{
return redirect::route('admin_posts_categories')->withError('Failed to add category.');
}
}else{
return redirect::route('admin_posts_categories')->withError('#Error Code : 4.');
}
}
, 나는 몇 가지 관련 질문을하고 싶습니다, 내 코드는 디자인 패턴을 수정 준수 않고, 어디 모델에, 리디렉션을 넣어해야하거나 컨트롤러에?
모델 내에 리디렉션 로직을 절대 배치하지 않아야합니다. laracasts.com에 방문하십시오. – Laurence
여러 줄에 걸쳐있는 코드 블록에 '인라인 코드 서식 지정'을 사용하지 마십시오. 이러한 경우 실제로 들쑥날쑥 해지기 때문에 사용하지 마십시오. 예를 들어, 코드를 선택하고 편집기의 툴바에서'{}'아이콘을 클릭하여 4- 스페이스 들여 쓰기 된 코드 블록을 사용하십시오. –