1

I'm trying to convert my image string to an actually image. Which I had put in the $response object.

But I want to add it to my $projects array, but I don't know how. However I did tried this:

class ProjectController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $projects = Project::all();
        foreach ($projects as $key => $value) {

            $response = new \stdClass();
            $response = Response::make($value->image, 200);
            $response->header('Content-Type', 'image/jpeg');

            $projects[] = $response;
        }

         return view('projects.index', ['projects' => $projects]);
    }

But it didn't work, because it didn't put the $response object in each project. Here is a picture to show you what I mean:

enter image description here

In the database you can see that I only have four projects.

enter image description here

3
  • You're making your array in json format. Commented Oct 14, 2015 at 0:07
  • 1
    What are you trying to do? If you're trying to take an image URL and return it as an actual image... why would you push it onto $projects and put that in a view ? ? Commented Oct 14, 2015 at 0:51
  • Because I want to loop through $projects. Because each project can has a image. Commented Oct 14, 2015 at 12:19

2 Answers 2

1

Replace this

$projects[] = $response;

With this..

array_push($projects, $response);

You could also do this..

$projects[count ($projects)]=$response;

Or just..

$projects[]=$response;

Take your pick...

Sign up to request clarification or add additional context in comments.

Comments

0

You can try array_push to add $response in $projects

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.