First of all hi my friend.
I want to display user profile with specific image according to user.
I tried this definition bu it did't work. Can you please show me any way to do this?
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('surname');
$table->string('email')->unique();
$table->string('password');
$table->string('title');
$table->binary('image');
$table->rememberToken();
$table->timestamps();
});
}
I would avoid storing user images in your database, so i'll propose two solutions, one is to save it inside the database, one is to actually store it on the filesystem and retrieve it (with a neat package)
$image_path = ''; // the path to the saved image
$image_type = pathinfo($image_path, PATHINFO_EXTENSION);
$image_binary = base64_encode(file_get_contents($image_path));
Unless you deny other image types i would also save it's extension
P.S: Remember to add a field into the user table if you are going to save the image type
Then to display it in an img tag
'data:image/' . $user->image_type . ';base64,' . $user->image
P.S: image/format is the mime of the image
The other way of doing it (you can still save images natively in laravel without using this) would be using this package, in case you would use images in other models, the documentation is pretty clear and straightforward so i'll leave that step for you