Laravel implode function on images array
How can I make this an implode function using array of images? I am getting an error of:
implode(): Invalid arguments passed
My controller:
public function store(Request $request)
{
$this->validate($request, [
'promotion_image' => 'required'
]);
if ($request->has('promotion_image'))
{
//Handle File Upload
$promotion = ;
foreach ($request->file('promotion_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/promotion_images',$fileNameToStore);
array_push($promotion, $fileNameToStore);
}
$fileNameToStore = serialize($promotion);
}
else
{
$fileNameToStore='noimage.jpg';
}
foreach ($promotion as $key => $value) {
$promotionImage = new Promotion;
$promotionImage->promotion_image = implode(' , ',$value);
$promotionImage->save();
}
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
My view:
@foreach($promotions as $promotion)
<tr>
//HERE IS WHERE THE IMAGE ARE VIEWED <th><img src="{{ asset('storage/promotion_images/' . $promotion->promotion_image) }}" style="width:50px;height:50px;"></th>
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
mysql arrays laravel implode
|
show 2 more comments
How can I make this an implode function using array of images? I am getting an error of:
implode(): Invalid arguments passed
My controller:
public function store(Request $request)
{
$this->validate($request, [
'promotion_image' => 'required'
]);
if ($request->has('promotion_image'))
{
//Handle File Upload
$promotion = ;
foreach ($request->file('promotion_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/promotion_images',$fileNameToStore);
array_push($promotion, $fileNameToStore);
}
$fileNameToStore = serialize($promotion);
}
else
{
$fileNameToStore='noimage.jpg';
}
foreach ($promotion as $key => $value) {
$promotionImage = new Promotion;
$promotionImage->promotion_image = implode(' , ',$value);
$promotionImage->save();
}
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
My view:
@foreach($promotions as $promotion)
<tr>
//HERE IS WHERE THE IMAGE ARE VIEWED <th><img src="{{ asset('storage/promotion_images/' . $promotion->promotion_image) }}" style="width:50px;height:50px;"></th>
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
mysql arrays laravel implode
To have it working you should be sure$valueis actually an array sinceimplode()function only accepts array as second argument. Put first line in foreach blockdd($value);to check what type of variable is that.
– Tpojka
Nov 25 '18 at 1:41
sir, can you edit the code please ? :( im trying hard since last night cant even get the right code.
– user10665294
Nov 25 '18 at 1:45
but what I want on my code is to insert the images in one column in my database thats why it has an implode function
– user10665294
Nov 25 '18 at 1:49
I am telling you where to start with debugging given error. Again, in first line in second foreach loop putvar_dump($value); exit;or shorterdd($value)and tell what has been got - what is$valueactually. It should be an array to get rid of implode error message.
– Tpojka
Nov 25 '18 at 2:09
it shows a text .."Desert_01.jpg" after dd($value)
– user10665294
Nov 25 '18 at 2:16
|
show 2 more comments
How can I make this an implode function using array of images? I am getting an error of:
implode(): Invalid arguments passed
My controller:
public function store(Request $request)
{
$this->validate($request, [
'promotion_image' => 'required'
]);
if ($request->has('promotion_image'))
{
//Handle File Upload
$promotion = ;
foreach ($request->file('promotion_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/promotion_images',$fileNameToStore);
array_push($promotion, $fileNameToStore);
}
$fileNameToStore = serialize($promotion);
}
else
{
$fileNameToStore='noimage.jpg';
}
foreach ($promotion as $key => $value) {
$promotionImage = new Promotion;
$promotionImage->promotion_image = implode(' , ',$value);
$promotionImage->save();
}
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
My view:
@foreach($promotions as $promotion)
<tr>
//HERE IS WHERE THE IMAGE ARE VIEWED <th><img src="{{ asset('storage/promotion_images/' . $promotion->promotion_image) }}" style="width:50px;height:50px;"></th>
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
mysql arrays laravel implode
How can I make this an implode function using array of images? I am getting an error of:
implode(): Invalid arguments passed
My controller:
public function store(Request $request)
{
$this->validate($request, [
'promotion_image' => 'required'
]);
if ($request->has('promotion_image'))
{
//Handle File Upload
$promotion = ;
foreach ($request->file('promotion_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/promotion_images',$fileNameToStore);
array_push($promotion, $fileNameToStore);
}
$fileNameToStore = serialize($promotion);
}
else
{
$fileNameToStore='noimage.jpg';
}
foreach ($promotion as $key => $value) {
$promotionImage = new Promotion;
$promotionImage->promotion_image = implode(' , ',$value);
$promotionImage->save();
}
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
My view:
@foreach($promotions as $promotion)
<tr>
//HERE IS WHERE THE IMAGE ARE VIEWED <th><img src="{{ asset('storage/promotion_images/' . $promotion->promotion_image) }}" style="width:50px;height:50px;"></th>
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
mysql arrays laravel implode
mysql arrays laravel implode
edited Jan 30 at 9:09
halfer
14.6k758114
14.6k758114
asked Nov 25 '18 at 1:14
user10665294
To have it working you should be sure$valueis actually an array sinceimplode()function only accepts array as second argument. Put first line in foreach blockdd($value);to check what type of variable is that.
– Tpojka
Nov 25 '18 at 1:41
sir, can you edit the code please ? :( im trying hard since last night cant even get the right code.
– user10665294
Nov 25 '18 at 1:45
but what I want on my code is to insert the images in one column in my database thats why it has an implode function
– user10665294
Nov 25 '18 at 1:49
I am telling you where to start with debugging given error. Again, in first line in second foreach loop putvar_dump($value); exit;or shorterdd($value)and tell what has been got - what is$valueactually. It should be an array to get rid of implode error message.
– Tpojka
Nov 25 '18 at 2:09
it shows a text .."Desert_01.jpg" after dd($value)
– user10665294
Nov 25 '18 at 2:16
|
show 2 more comments
To have it working you should be sure$valueis actually an array sinceimplode()function only accepts array as second argument. Put first line in foreach blockdd($value);to check what type of variable is that.
– Tpojka
Nov 25 '18 at 1:41
sir, can you edit the code please ? :( im trying hard since last night cant even get the right code.
– user10665294
Nov 25 '18 at 1:45
but what I want on my code is to insert the images in one column in my database thats why it has an implode function
– user10665294
Nov 25 '18 at 1:49
I am telling you where to start with debugging given error. Again, in first line in second foreach loop putvar_dump($value); exit;or shorterdd($value)and tell what has been got - what is$valueactually. It should be an array to get rid of implode error message.
– Tpojka
Nov 25 '18 at 2:09
it shows a text .."Desert_01.jpg" after dd($value)
– user10665294
Nov 25 '18 at 2:16
To have it working you should be sure
$value is actually an array since implode() function only accepts array as second argument. Put first line in foreach block dd($value); to check what type of variable is that.– Tpojka
Nov 25 '18 at 1:41
To have it working you should be sure
$value is actually an array since implode() function only accepts array as second argument. Put first line in foreach block dd($value); to check what type of variable is that.– Tpojka
Nov 25 '18 at 1:41
sir, can you edit the code please ? :( im trying hard since last night cant even get the right code.
– user10665294
Nov 25 '18 at 1:45
sir, can you edit the code please ? :( im trying hard since last night cant even get the right code.
– user10665294
Nov 25 '18 at 1:45
but what I want on my code is to insert the images in one column in my database thats why it has an implode function
– user10665294
Nov 25 '18 at 1:49
but what I want on my code is to insert the images in one column in my database thats why it has an implode function
– user10665294
Nov 25 '18 at 1:49
I am telling you where to start with debugging given error. Again, in first line in second foreach loop put
var_dump($value); exit; or shorter dd($value) and tell what has been got - what is $value actually. It should be an array to get rid of implode error message.– Tpojka
Nov 25 '18 at 2:09
I am telling you where to start with debugging given error. Again, in first line in second foreach loop put
var_dump($value); exit; or shorter dd($value) and tell what has been got - what is $value actually. It should be an array to get rid of implode error message.– Tpojka
Nov 25 '18 at 2:09
it shows a text .."Desert_01.jpg" after dd($value)
– user10665294
Nov 25 '18 at 2:16
it shows a text .."Desert_01.jpg" after dd($value)
– user10665294
Nov 25 '18 at 2:16
|
show 2 more comments
1 Answer
1
active
oldest
votes
If I get you right, try without foreach loop
if (count($promotion)) {
$implodedPromotion = implode(' , ', $promotion);
$promotionImage = new Promotion;
$promotionImage->promotion_image = $implodedPromotion;
$promotionImage->save();
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
return redirect('/admin/airlineplus/promotions')->with('error', 'Something went wrong.');
Supplemental:
If you have that value in your view and want to show those images, you should do the next:
@foreach($promotions as $promotion)
@php
$imagesImploded = $promotion->promotion_image;
$imagesExploded = explode(',', $imagesImploded);
@endphp
<tr>
@foreach($imagesExploded as $image)
<th><img src="{{ asset('storage/promotion_images/' . trim($image)) }}" style="width:50px;height:50px;"></th>
@endforeach
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463859%2flaravel-implode-function-on-images-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If I get you right, try without foreach loop
if (count($promotion)) {
$implodedPromotion = implode(' , ', $promotion);
$promotionImage = new Promotion;
$promotionImage->promotion_image = $implodedPromotion;
$promotionImage->save();
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
return redirect('/admin/airlineplus/promotions')->with('error', 'Something went wrong.');
Supplemental:
If you have that value in your view and want to show those images, you should do the next:
@foreach($promotions as $promotion)
@php
$imagesImploded = $promotion->promotion_image;
$imagesExploded = explode(',', $imagesImploded);
@endphp
<tr>
@foreach($imagesExploded as $image)
<th><img src="{{ asset('storage/promotion_images/' . trim($image)) }}" style="width:50px;height:50px;"></th>
@endforeach
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
add a comment |
If I get you right, try without foreach loop
if (count($promotion)) {
$implodedPromotion = implode(' , ', $promotion);
$promotionImage = new Promotion;
$promotionImage->promotion_image = $implodedPromotion;
$promotionImage->save();
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
return redirect('/admin/airlineplus/promotions')->with('error', 'Something went wrong.');
Supplemental:
If you have that value in your view and want to show those images, you should do the next:
@foreach($promotions as $promotion)
@php
$imagesImploded = $promotion->promotion_image;
$imagesExploded = explode(',', $imagesImploded);
@endphp
<tr>
@foreach($imagesExploded as $image)
<th><img src="{{ asset('storage/promotion_images/' . trim($image)) }}" style="width:50px;height:50px;"></th>
@endforeach
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
add a comment |
If I get you right, try without foreach loop
if (count($promotion)) {
$implodedPromotion = implode(' , ', $promotion);
$promotionImage = new Promotion;
$promotionImage->promotion_image = $implodedPromotion;
$promotionImage->save();
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
return redirect('/admin/airlineplus/promotions')->with('error', 'Something went wrong.');
Supplemental:
If you have that value in your view and want to show those images, you should do the next:
@foreach($promotions as $promotion)
@php
$imagesImploded = $promotion->promotion_image;
$imagesExploded = explode(',', $imagesImploded);
@endphp
<tr>
@foreach($imagesExploded as $image)
<th><img src="{{ asset('storage/promotion_images/' . trim($image)) }}" style="width:50px;height:50px;"></th>
@endforeach
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
If I get you right, try without foreach loop
if (count($promotion)) {
$implodedPromotion = implode(' , ', $promotion);
$promotionImage = new Promotion;
$promotionImage->promotion_image = $implodedPromotion;
$promotionImage->save();
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
return redirect('/admin/airlineplus/promotions')->with('error', 'Something went wrong.');
Supplemental:
If you have that value in your view and want to show those images, you should do the next:
@foreach($promotions as $promotion)
@php
$imagesImploded = $promotion->promotion_image;
$imagesExploded = explode(',', $imagesImploded);
@endphp
<tr>
@foreach($imagesExploded as $image)
<th><img src="{{ asset('storage/promotion_images/' . trim($image)) }}" style="width:50px;height:50px;"></th>
@endforeach
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
edited Nov 25 '18 at 11:32
answered Nov 25 '18 at 2:52
TpojkaTpojka
4,77921832
4,77921832
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
add a comment |
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
IT WORKS!!!!! But my images are not showing in view
– user10665294
Nov 25 '18 at 3:23
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
sir all is working now but my last problem is I cannot show the images in my view pls help for the last time to finish my project
– user10665294
Nov 25 '18 at 4:02
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
Sir @Tpojka , I edit the code above added the VIEW. there you will see how i view my images. please see and help me for the last time for me to marked your answer as solved
– user10665294
Nov 25 '18 at 4:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463859%2flaravel-implode-function-on-images-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To have it working you should be sure
$valueis actually an array sinceimplode()function only accepts array as second argument. Put first line in foreach blockdd($value);to check what type of variable is that.– Tpojka
Nov 25 '18 at 1:41
sir, can you edit the code please ? :( im trying hard since last night cant even get the right code.
– user10665294
Nov 25 '18 at 1:45
but what I want on my code is to insert the images in one column in my database thats why it has an implode function
– user10665294
Nov 25 '18 at 1:49
I am telling you where to start with debugging given error. Again, in first line in second foreach loop put
var_dump($value); exit;or shorterdd($value)and tell what has been got - what is$valueactually. It should be an array to get rid of implode error message.– Tpojka
Nov 25 '18 at 2:09
it shows a text .."Desert_01.jpg" after dd($value)
– user10665294
Nov 25 '18 at 2:16