1
これらは私が持っているものです:id
、judul
、isi
、created_at
、updated_at
:これらのフィールドを持っているlamanInformasi
という名前Laravel 5.2 - データベースへのファイルのアップロード
データベーステーブル、。
ユーザーが複数の文書や画像ファイルをアップロードすることができ、そしてファイルがデータベースに保存されます。
これは私が欲しいものです。ファイル名はisi
フィールドに保存され、ファイル自体はpropic
という名前のフォルダに保存されます。ユーザーはまた、ウェブサイト上のデータベースからすべてのデータを表示することができます。
これらは私のコードです:
create.blade.php
<form action="[email protected]" method="post" enctype="multipart/form-data">
<input type="file" name="image"><br />
<input type="submit" name="submit" value="Submit">
</form>
lamanInformasiController.php
public function index(Request $request)
{
$file = new file;
if (Input::hasFile('image'))
{
$destinationPath = public_path().'/propic/';
$name = Input::file('image')->getClientOriginalName();
$extension = Input::file('image')->getClientOriginalExtension();
$file = Input::file('image')->move($destinationPath, $name . "." . $extension);
}
$file -> isi = $request->get($file);
$file -> save();
$lamanInformasi = LamanInformasi::all();
return view('upload.index', compact('lamanInformasi'));
}
index.blade.php
<table class="table table-striped table-bordered" border= "1px solid black">
<thead>
<tr>
<td>ID</td>
<td>Judul</td>
<td>Isi</td>
<td>Created At</td>
<td>Updated At</td>
</tr>
</thead>
<tbody>
@foreach($$lamanInformasi as $key => $value)
<tr>
<td>{{$value->id}}</td>
<td>{{$value->judul}}</td>
<td>{{$value->isi}}</td>
<td>{{$value->created_at}}</td>
<td>{{$value->updated_at}}</td>
</tr>
@endforeach
</tbody>
</table>
私はそれを実行すると、私はこのエラーを持っている:
ErrorException in ParameterBag.php line 90:
array_key_exists(): The first argument should be either a string or an integer
私はこれを持ってParameterBag line 89-91
public function get($key, $default = null)
{
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
}
にこれらが私の質問です:
方法〜fそのixのエラー?ファイルをアップロードするコードを作成しましたか?私は同様のコードを試したので、うまくいきません。ありがとう
array_key_existsはnull、float、boolean、および 'integer-indicating string'キーを処理しますが、boolとfloatの場合、配列オフセットとして使用すると変換される方法は一致しません。 – FullStack
@FullStack申し訳ありませんが、わかりません。私は何をすべきか? –
このページを見るhttp://php.net/manual/en/function.array-key-exists.php#90687 – FullStack