i want to save image URL in database. I have migration
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->binary('image')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('image');
});
}
}
in my view i have input field
<div class="form-group">
<label for="imageUrl">Image URL</label>
<input type="text" class="form-control" id="image" name="image" placeholder="Image url">
</div>
In my controller i have this code>
public function store(Request $request){
$post = Post::create($request->all());
$title = $post->title;
$id = 0;
$slug = str_slug($title);
$allSlugs = $this->getRelatedSlugs($slug, $id);
if (!$allSlugs->contains('slug', $slug)){
$post->slug = $slug;
}
else{
for ($i = 1; $i <= 10; $i++) {
$newSlug = $slug.'-'.$i;
if (!$allSlugs->contains('slug', $newSlug)) {
$post->slug = $newSlug;
}
}
}
$post->save();
return redirect('/home');
When i add image url in input field in the database image field is always null. How i can add image url in database?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire