에서 나는 Laravel에서 초보자입니다, 나는 붙어입니다 :) 나는 오히려 간단한 웹 사이트와 의상에 대한 간단한 CMS를 구축하고Laravel 출력 단일 행 데이터베이스
. 사이트 전체에 걸쳐 편집 할 수 있도록하려는 모든 텍스트에 대한 데이터베이스를 만들었습니다. 모든 CRUD가 작동하지만 블레이드가있는 데이터베이스의 내용을 실제보기로 출력 할 수 없습니다. 변수가 없다는 오류가 발생합니다.
{{$ text -> "특정 ID를 삽입하십시오"}} 내 테이블에는 사이트에 해당하는 텍스트 콘텐츠를 식별 할 수있는 ID 문자열이 있습니다.
텍스트 요소의 CRUD를 처리하는 MainController와 TextController가 있습니다.
나는 아마도 간단한 것을 잊어 버릴 것이지만, 나는 그것을 해결할 수없는 것 같습니다.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Text;
use Session;
class TextController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$texts = Text::all();
return view('texts.index')->withTexts($texts);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, array(
'content' => 'required'
));
$text = new Text;
$text->content = $request->content;
$text->save();
return redirect()->route('texts.index');
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$text = Text::find($id);
return view('texts.edit')->withText($text);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$text = Text::find($id);
$this->validate($request, array(
'content' => 'required'
));
$text->content = $request->content;
$text->save();
Session::flash('success', 'Teksten blev ændret!');
return redirect()->route('texts.index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
나는 내가 MainController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use Mail;
use Illuminate\Support\Facades\DB;
use Session;
use App\Text;
class MainController extends Controller
{
public function index(){
return view('index');
}
뭔가를 그 할 수없는 오전 생각?
미리 감사드립니다. 세션 콘텐츠 with()
깜박를 사용
이 동영상은 도움이됩니다. https://laracasts.com/series/laravel-from-scratch-2017/episodes/5 및 https://laracasts.com/series/laravel-from -scratch-2017/episodes/8 –