public function store(Request $request) { $user = User::find($request['user']['sub']); $center = new Center(); DB::transaction(function () use($request, $center, $user) { if ($request->has('location') && isset($request->input('location')['address_components'])) { $geo = $this->processGeoValue($request->input('location')); $location = Location::firstOrCreate($geo); $location->save(); $center->location_id = $location->id; } $center->title = $request->input('title'); $center->description = $request->input('description'); $center->details = $request->input('details'); $center->main_picture = $request->input('main_picture'); $center->twitter_hashtag = $request->input('twitter_hashtag'); $center->instagram_hashtag = $request->input('instagram_hashtag'); $center->save(); }); return $center; }
public function addLogoMedia(Request $request) { if (!$request->hasFile('file')) { return Response::json(['error' => 'No File Sent']); } if (!$request->file('file')->isValid()) { return Response::json(['error' => 'File is not valid']); } $file = $request->file('file'); $v = Validator::make($request->all(), ['file' => 'required|mimes:jpeg,jpg,png|max:8000']); if ($v->fails()) { return Response::json(['error' => $v->errors()]); } $user = User::find($request['user']['sub']); $image = Media::create(['name' => $request->file('file')->getClientOriginalName(), 'ext' => $request->file('file')->guessExtension(), 'title' => $request->input('title'), 'description' => $request->input('description'), 'url' => $request->input('url'), 'user_id' => $user->id, 'type' => 'DATA']); $filename = 'media_' . md5(strtolower(trim($image->name))) . '_' . $image->id . '.' . $image->ext; $image->name = $filename; $image->save(); Storage::disk('local')->put($filename, File::get($file)); Storage::disk('s3-aruma')->put('/aruma/' . $filename, file_get_contents($file), 'public'); return Response::json(['OK' => 1, 'filename' => $image->name, 'media_id' => $image->id]); }
public function assignRoles(Request $request) { $user = User::find($request['user']['sub']); if ($user->hasRole('crud_user')) { DB::transaction(function () use($request) { $roles = $request->input('roles'); $user_id = $request->input('userId'); DB::table('users_roles')->where('user_id', '=', $user_id)->delete(); foreach ($roles as $role) { $userRole = UserRole::firstOrCreate(array('user_id' => $user_id, 'role_id' => $role['id'])); } }); } else { return response()->json(['message' => 'No tienes permisos para esta operacion'], 401); } return response()->json(['message' => 'Permisos asignados'], 200); }
public function removePicture(Request $request, $organizationId, $mediaId) { $user = User::find($request['user']['sub']); $organization = Organization::find($organizationId); DB::transaction(function () use($request, $organization, $mediaId) { if ($organization->media_id == $mediaId) { $organization->media_id = null; $organization->main_picture = null; $organization->save(); } DB::table('organizations_medias')->where('organization_id', '=', $organization->id)->where('media_id', '=', $mediaId)->delete(); Media::destroy($mediaId); }); }
public function removePicture(Request $request, $activityId, $mediaId) { $user = User::find($request['user']['sub']); $activity = Activity::find($activityId); DB::transaction(function () use($request, $activity, $mediaId) { if ($activity->media_id == $mediaId) { $activity->media_id = null; $activity->main_picture = null; $activity->save(); } DB::table('activities_medias')->where('activity_id', '=', $activity->id)->where('media_id', '=', $mediaId)->delete(); Media::destroy($mediaId); }); }