Home>

I want to resolve the error.
I'm creating an Instagram-style app with laravel.
I want to change the image data to be saved in the DB instead of the file so that the posted photos will not disappear, but the following error occurred.

The error message that is occurring
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_PARSE)
Parse error: syntax error, unexpected'$post' (T_VARIABLE)

"Parse error: syntax error, unexpected'$post'(T_VARIABLE)"
Corresponding source code

app/Http/Controllers/PostsController.php

<? php
namespace App \ Http \ Controllers;
use App \ Post;
use Auth;
use Validator;
use Illuminate \ Http \ Request;
class PostsController extends Controller
{
   public function __construct ()
    {
        $this->middleware ('auth');
    }
      public function index ()
    {
        $posts = Post :: limit (10)
            ->orderBy ('created_at','desc')
            ->get ();
        return view ('post/index', ['posts' =>$posts]);
    }

    public function new ()
    {
        return view ('post/new');
    }
    public function store (Request $request)
    {
        $validator = Validator :: make ($request->all (), ['caption' =>'required | max: 255','photo' =>'required']);

        if ($validator->fails ())
        {
            return redirect ()->back ()->withErrors ($validator->errors ())->withInput ();
        }

        $post = new Post;
        $post->caption = $request->caption;
        $post->user_id = Auth :: user ()->id;
    $Post->image = base64_encode (file_get_contents ($request->photo));
        $post->save ();

        return redirect ('/');
    }
   public function destroy ($post_id)
    {
        $post = Post :: find ($post_id);
        $post->delete ();
        return redirect ('/');
    }
}
What I tried

$post->image = base64_encode (file_get_contents ($request->photo));

I did a spelling check and a syntax check for this sentence, but couldn't find a clue to the solution.
I am a beginner and unfamiliar, so I would appreciate it if you could give me some advice.

Supplementary information (FW/tool version, etc.)

Development environment: cloud9
Language used: laravel
MacOS