我得到這個錯誤,我不無爲什麼 部分ID和書籍之間的界限laravel未定義的變量:
未定義的變量:節(查看:C:\ XAMPP \ htdocs中\ LIB \資源\意見\書\ create_book.blade.php)
鏈接<a href="{{url('admin_book/createbook',$section->id)}}"class="btn btn-success">New Book</a>
我create_book.blade.php
{!! Form::open(['url'=>'admin_book/store','method'=>'POST','files'=>'true']) !!}
{!! Form::hidden('section_id',$section->id) !!}
<div class="form-group ">
{!! Form::label('Book Title', 'Enter the Title of Book:') !!}
{!! Form::text("book_title",'',['class'=>'form-control']) !!}
</div>
<div class="form-group ">
{!! Form::label('Book Edition', 'Enter the Edition of Book:') !!}
{!! Form::text("book_edition",'',['class'=>'form-control']) !!}
</div>
<div class="form-group ">
{!! Form::label('Book Description', 'Enter the Description of Book:') !!}
{!! Form::textarea("book_description",'',['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('upload', 'Upload an Image:') !!}
{!! Form::file('image','',['class'=>'form-control']) !!}
</div>
<br>
<div class="form-group">
{!! Form::submit('Create',['class'=>'btn btn-info btn-block']) !!}
</div>
{!! Form::close() !!}
和我booksControllers
public function create()
{
return view('books.create_book');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$book_title = $request ->input('book_title');
$book_edition = $request ->input('book_edition');
$book_description = $request ->input('book_description');
$file = $request ->file('image');
$destinationPath = 'images';
$filename = $file ->getClientOriginalName();
$file ->move($destinationPath,$filename);
$section_id = $request -> section_id;
$new_book = new Book;
$new_book ->book_title = $book_title;
$new_book ->book_edition = $book_edition;
$new_book ->book_description = $book_description;
$new_book ->image_name = $filename;
$new_book ->section_id = $section_id;
$new_book ->save();
return redirect('admin_book/'.$section_id);
}
和我的路線
Route::get('admin_book/createbook','[email protected]');
您沒有將'$ section'傳遞給您的視圖:'return view('books.create_book');'您需要有一個' - > with([「section」=> $ section]);'可以在你的視圖中使用它。 –
我得到這個錯誤未定義的屬性:Illuminate \ Database \ Eloquent \ Collection :: $ id(View:C:\ xampp \ htdocs \ lib \ resources \ views \ books \ create_book.blade.php)當我把這個$ section =第::所有();返回視圖('books.create_book') - > with([「section」=> $ section]); – fido
你正在返回所有'Sections',它們在一個數組中......所以'$ section [0] - > id',不要'$ section-> id'。 –