Comments (10)
Hey Devin,
Thanks for bringing this to my attention. The reason that this wasn't working for you, was because of a bug in the javascript file. This is now fixed, if you want to update your code. Alternatively, you can use the event handler method below if you don't feel like doing an update. With that being said, here is how you can accomplish your goal:
EVENT HANDLER (preferred - this keeps your code nicely decoupled)
- In your app/Providers/EventServiceProvider.php file, add a listener:
protected $listen = [
'Jasekz\Laradrop\Events\FileWasUploaded' => [
'App\Handlers\Events\LaradropFileWasUploaded',
],
];
-
Generate the handler with:
artisan handler:event 'App\Handlers\Events\LaradropFileWasUploaded' --event='Jasekz\Laradrop\Events\FileWasUploaded'
-
In the newly generated handler file - app/Handlers/Events/LaradropFileWasUploaded.php, change:
use App\Events\Jasekz\Laradrop\Events\FileWasUploaded
to
use Jasekz\Laradrop\Events\FileWasUploaded
-
In the
handle()
function, you can now access the uploaded file object and perform your business logic as needed. For example:
public function handle(FileWasUploaded $event) {
$file = $event->data['file'];
$file->findimage = 3;
$file->update();
}
CONTROLLER OVERRIDE METHOD
- Create the controller (as you have), but you can skip all the laradrop code and just add your business logic. The parent returns a file object you can utilize. For example:
public function store() {
try {
$file = parent::store();
$file->findimage = 1;
$file->update();
}
catch (Exception $e) {
return $this->handleError($e);
}
}
- Make sure your controller is name spaced correctly:
namespace App\Http\Controllers;
- In your view, all you need is the upload handler.
<div class="laradrop"
laradrop-upload-handler="/mediaStore"
laradrop-csrf-token="{{ csrf_token() }}">
</div>
I didn't get into the Auth::user() functionality because that's outside of the scope, but you should be able to use it in the normal Laravel way. Let me know if this helps and/or if the issue persists.
Thanks,
Zig
from laradrop.
Hi Zig and thanks for the response. I tried both methods and they seem to not be working. I would prefer the controller override method, as I can then get it to work as I need it, but I am still not hitting my controller.
I have this code below. My Goal is to assign findimage the users ID. So that I can collect only images assigned to that user. I do not want to use folders. Its one image per user.
<div class="laradrop"
laradrop-file-source="/mediaIndex"
laradrop-upload-handler="/mediaStore"
laradrop-csrf-token="{{csrf_field()}}">
</div>
This is where I instantiate my laradrop.
and my routes
//User Media Files
Route::get('mediaIndex', 'UserMediaController@index');
Route::post('mediaStore', 'UserMediaController@store');
But for some reason it is still not getting to that controller. I also want to crop and resize the image in the controller so over riding it would be my best option.
But am at a loss as to why this is not happening. New controller below
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Jasekz\Laradrop\Http\Controllers\LaradropController;
use Input, Auth;
class UserMediaController extends LaradropController {
/**
* Upload and store new file.
*
* @return JsonResponse
*/
public function store()
{
if (!Auth::user()->currentTeam()){
$eitherTeamOrUser = \Auth::user()->finduser;
}
elseif(Auth::user()->currentTeam()){
$eitherTeamOrUser = \Auth::user()->currentTeam()->findteam;
}
try {
$file = parent::store();
$file->findimage = $eitherTeamOrUser;
$file->update();
}
catch (Exception $e) {
return $this->handleError($e);
}
}
from laradrop.
Oh yes and this command php artisan handler:event 'App\Handlers\Events\LaradropFileWasUploaded' --event='Jasekz\Laradrop\Events\FileWasUploaded'
isnt working for some reason. Am on 5.3
from laradrop.
I'm testing this on 5.3 now and expect to have a solution for you shortly, but let me know if you find something before then. Thanks for taking the time to work through this.
from laradrop.
Try this:
- Delete the
/public/vendor/jasekz
directory. - Re-install the latest version of laradrop.
- Re-run
artisan vendor:publish
Let me know how it goes.
from laradrop.
Hi Zig. It is wierd, am still not hitting my controller. I think the solution to my problem will be to create a trait for the images, then on successfull upload, send the image ID to my trait and just run a raw DB query to update this field in the Database, then return back the way you have it working. Am trying it out now. Such a rad package :D
from laradrop.
Okay :D This is my final answer, yes I am sure, Lock it in! ;) Found best solution here https://laracasts.com/discuss/channels/general-discussion/l5-service-provider-for-sharing-view-variables
from laradrop.
Ok, thanks, Dev. Yeah, that's strange because I can get this to work as expected on my end. I'll go ahead and close this out, but one more thing you may want to verify in your browser's network inspector, is that when you do an upload, the ajax call actually goes to /mediaStore, and not /laradrop. If it doesn't, it's most likely that you're running off of the old laradrop.js
file.
from laradrop.
Just a last bit of info regarding this. I was an idiot and overlooked the easiest option.
onSuccessCallback(){
do an ajax request to my controller
}
from laradrop.
👍
from laradrop.
Related Issues (20)
- New Feature Request: can laradrop support paginator? HOT 4
- Boot method error HOT 2
- making thumbnails rotated? HOT 1
- Compatibility with Laravel 5.3 HOT 5
- New Feature Request: multi users and alert equal file name? HOT 1
- After installing into an existing project laradrop gives this error on console HOT 18
- would you consider using this vue-dropzone instead? HOT 1
- Integrete with CKEDITOR or TINYMCE 4? HOT 1
- http://localhost/laradrop/containers NOT FOUND HOT 3
- artisan vendor:publish do not publish related files HOT 8
- costumize index method HOT 5
- laradrop.js HOT 2
- Is there a way to limit extensions? HOT 1
- How do I show the actual progress of the file upload? HOT 2
- Folder image location. HOT 3
- How to set custom location for each user. HOT 6
- Display Folder Images on Page Load HOT 2
- its not publishing the files needed HOT 10
- Laradrop does not support baum/baum v2 (for Laravel 5.8) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laradrop.