-2

i'm trying to make web services, i have done with string or numeric data. now i need to pass image data through my web services. how should i add the table using php laravel code?

i tried to use blob when i created the table, but it throws me an error saying that method blob does not exist

Schema::create('testings', function (Blueprint $table) {
        $table->increments('id');
        $table->string('description');
        $table->blob('photo');
        $table->timestamps();
    });

i expect the migration to create the table containing the photo column which can save the photo file when user upload

thanks for your help :)

rondi
  • 71
  • 11
  • 5
    Wouldn't you like to upload the file and just store the link? – ka_lin Jul 24 '19 at 07:44
  • yeah it is, so i need to insert image to a table in it – rondi Jul 24 '19 at 07:49
  • 1
    You should not upload the file itself to the database - upload the file to the server. Then store the filepath and its name in the database. – Qirel Jul 24 '19 at 07:49
  • so i should upload the file to a server? is there anyway to store it in my db? or it really can't? – rondi Jul 24 '19 at 07:55
  • 1
    You can, but that doesn't mean you should. It's much better to upload the file to the server, and just store the path/filename in the DB. – Qirel Jul 24 '19 at 08:01
  • how can i get the path? when i hit using postman binary file, what i got is NULL – rondi Jul 24 '19 at 08:50

1 Answers1

1

There is no "blob" name. Instead try:

$table->binary('photo');
pr1nc3
  • 8,108
  • 3
  • 23
  • 36
  • when we use postman to send, we can choose type "file". can we use this binary for that file? – rondi Jul 24 '19 at 07:48
  • I would suggest the binary which is in the 4th tab of body parameters in postman. type `file` would work but careful to handle it as a form-data value. – pr1nc3 Jul 24 '19 at 07:50
  • so when i need to store like 'name' , 'description' , 'photo'.. i should make 1 services to store 'name' and 'description', then make another one to store binary for 'photo'? – rondi Jul 24 '19 at 07:53
  • Well how i do it is that my "uploaders" are always a separate service. They are classes that do only that and are injected where i need them. – pr1nc3 Jul 24 '19 at 07:54
  • so i just need to create the binary column? and use binary tab to insert into it? – rondi Jul 24 '19 at 07:56
  • Yes pretty much. If you have more code related questions please open another question posting your code there explaining what you have tried and what is the problem . This question was about issues in your migration. – pr1nc3 Jul 24 '19 at 07:57