Laravel 2019-08-30 16:57

|
Ahmed Magdi 2019-08-30 16:57:22
laravel_discuss-12051.jpg
That fetch data code
gplane 2019-08-30 17:05:23
Open browser’s Developer Tools and check the response.
rebory 2019-08-30 17:57:55
laravel_discuss-12057.jpg
model
rebory 2019-08-30 17:58:17
/**
* @param Request $request
*/
public function uploadFiles(Request $request)
{
if(!$request->ajax()) {
abort(404);
}
$inputs = $request->all();

if(!isset($inputs[‘album_id’]) || $inputs[‘album_id’] == null) {
abort(404);
}

$albumID = $inputs[‘album_id’];
$result = Album::where(‘id’, $albumID)->first();

if($result == null) {
abort(404);
}

$galleryArr = [];

if($request->hasFile(‘file’)) {
$files = $request->file;
if(count($files) > 0) {

$destinationPath = public_path(‘uploads/gallery/’);
$thumbPath = public_path(‘uploads/thumbs’);
$xsThumbPath = public_path(‘uploads/xs-thumbs’);

foreach($files as $image) {
$originalName = $image->getClientOriginalName();
$extension = $image->getClientOriginalExtension();
$size = $image->getSize();

if(!in_array($extension, [‘jpg’, ‘jpeg’, ‘png’ , ‘gif’])) {
continue;
}
#Not more than 5MB.
if($size >= 5242880) {
continue;
}

$imageName = randomName(10) . ‘.’. $extension;
#saving thumbs

$thumbImg = Image::make($image->getRealPath())->resize(370, 280);
$thumbImg->save($thumbPath.’/’.$imageName, 80);

$xsThumbImg = Image::make($image->getRealPath())->resize(370, 280);
$xsThumbImg->save($xsThumbPath. ‘/’ .$imageName, 80);

$galleryArr[] = [
‘album_id’ => $albumID,
‘original_name’ => $originalName,
‘image’ => $imageName
];
$image->move($destinationPath, $imageName);
}

(new Gallery)->insert($galleryArr);
}
}
}

L 2019-08-30 17:58:18
laravel_discuss-12059.jpg

L 2019-08-30 17:58:21
laravel_discuss-12060.jpg

L 2019-08-30 17:58:25
laravel_discuss-12061.jpg

L 2019-08-30 17:58:55
why i can’t get session from another controller
L 2019-08-30 17:59:14
i had used put and get the same result
rebory 2019-08-30 17:59:35
laravel_discuss-12067.jpg

rebory 2019-08-30 18:00:24
{{ Form::open([‘url’ => route(‘gallery.upload’),
‘method’ => ‘POST’,
‘files’ => true,
‘enctype’ => ‘multipart/form-data’,
‘class’ => ‘dropzone’,
‘id’ => ‘my-dropzone’
])
}}

{{ Form::hidden(‘album_id’, $albumID, [‘id’ => ‘album_id’]) }}

{{ Form::close() }}

</div>
</div>
</div>
</div>

</div>
<!– /Row –>
</div> <!– end container –>
@endsection

@section(‘scripts’)

<script>
$(function(){
Dropzone.options.myDropzone = {
paramName: ‘file’,
acceptedFiles: ‘.jpg, .jpeg, .png’,
maxFiles:10,
parallelUploads: 100,
maxFilesize: 5,
uploadMultiple: true,
addRemoveLinks: true,
init:function() {

let myDropzone = this;
$.get(‘{{ route(‘server.image’, [‘id’ => $albumID]) }}’, function(data) {
$.each(data.images, function (key, value) {
var file = {name: value.original, size: value.size, file_name: value.server};
myDropzone.options.addedfile.call(myDropzone, file);
// myDropzone.options.thumbnail.call(myDropzone, file, ‘../uploads/thumbs/’ + value.server);
myDropzone.options.thumbnail.call(myDropzone, file, ‘../uploads/xs-thumbs/’ + value.server);
myDropzone.emit(“complete”, file);
});
});

myDropzone.on(‘sendingmultiple’, function(data, xhr, formData) {
// this will get sent
formData.append(‘album_id’, $(‘#album_id’).val());
// this won’t
let myForm = document.querySelector(‘form’);
formData = new FormData(myForm);
});

myDropzone.on(“removedfile”, function(file) {

$.ajax({
type: ‘POST’,
url: ‘{{ route(‘upload.delete’) }}’,
data: {
file_name: file.file_name,
_token: $(‘meta[name=”csrf-token”]’).attr(‘content’)
},
dataType: ‘html’,
success: function(data){
let response = JSON.parse(data);
if(response.status == 200) {}
}
});

} );

myDropzone.on(‘completemultiple’, function () {
window.location.reload();
});

}
};
});
</script>

L 2019-08-30 18:00:29
laravel_discuss-12070.jpg

L 2019-08-30 18:00:43
i got the null result
rebory 2019-08-30 18:02:14
i can’t understand where is error when i upload images via dropzone images sucessfully uploaded and move to folder with successfully rename but not save in database
rebory 2019-08-30 18:03:26
laravel_discuss-12075.jpg

L 2019-08-30 18:03:41
laravel_discuss-12076.jpg

L 2019-08-30 18:04:08
i get the sring , not the value
L 2019-08-30 18:04:19
how can i get the string
L 2019-08-30 18:04:45
laravel_discuss-12079.jpg

rebory 2019-08-30 18:07:35
When i debug no issue it accept miltiple images and upload img intervention in controller resize or rename images sucessfully but not inserted in table
L 2019-08-30 18:08:11
laravel_discuss-12082.jpg

rebory 2019-08-30 18:08:12
$galleryArr[] = [
‘album_id’ => $albumID,
‘original_name’ => $originalName,
‘image’ => $imageName
];
$image->move($destinationPath, $imageName);
}

(new Gallery)->insert($galleryArr);

rebory 2019-08-30 18:09:26
(new Gallery)->insert($galleryArr);
rebory 2019-08-30 18:10:04
that code not work and page refresh dd not working in console
rebory 2019-08-30 18:11:45
yes
rebory 2019-08-30 18:12:12
protected $fillable = [
‘album_id’,
‘original_name’,
‘image’
];
rebory 2019-08-30 18:14:32
laravel_discuss-12096.jpg

L 2019-08-30 18:17:18
laravel_discuss-12101.jpg

L 2019-08-30 18:17:24
laravel_discuss-12102.jpg

L 2019-08-30 18:17:38
still can’t get the session
StanleyMasinde 2019-08-30 18:20:06
Ahmed Magdi 2019-08-30 16:57:22
That fetch data code

1. Laravel is returning Json you don’t need to convert it again
2. Please use the Axios library already included in your project

L 2019-08-30 18:22:05
laravel_discuss-12107.jpg

L 2019-08-30 18:22:15
the same result
rebory 2019-08-30 18:48:38
laravel_discuss-12109.jpg

rebory 2019-08-30 18:49:32
i drop there three files what it save only first one
rebory 2019-08-30 18:51:01
laravel_discuss-12112.jpg

rebory 2019-08-30 18:56:08
how i share with u now
rebory 2019-08-30 18:56:29
i pate my controller pastebin.com
rebory 2019-08-30 18:56:50
https://pastebin.com/HpQCwzW0

[PHP] GalleryController – Pastebin.comPastebin
rebory 2019-08-30 18:59:28
sorry i dont understand
rebory 2019-08-30 19:01:58
ok wait
rebory 2019-08-30 19:09:36
laravel_discuss-12131.jpg

rebory 2019-08-30 19:10:59
laravel_discuss-12132.jpg

rebory 2019-08-30 19:13:58
sorry
rebory 2019-08-30 19:14:24
some time my head in deadlock
rebory 2019-08-30 19:26:33
Ok bro
rebory 2019-08-30 19:28:14
I used dropzone
rebory 2019-08-30 19:28:22
And upload multiple
khalinxyz 2019-08-30 19:56:02
rebory 2019-08-30 19:09:36

Check spatie media library

rebory 2019-08-30 20:00:10
khalinxyz 2019-08-30 19:56:02
Check spatie media library

I know about this package but my project almost complete , i want finish this with this code

|