Anonymous Anonymous - 21 days ago
100 0

This is my whole class.
Forgot to say that this is in a package.
So this is located at /packages/corium/mediaManager

PHP

This is my whole class

<?php
namespace Corium\MediaManager;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
use DB;

class MediaManagerController extends Controller
{
  public function __construct()
  {
    $this->middleware('auth');
  }
  public function index(Request $request)
  {
    
    return view('coriumMediaManager::main')->with('pageActive', 'coriumMediaManager')->with('nameTree', 'Media Manager > View')->with('userName', $request->user()->name)->with('email', $request->user()->email);
  }
  public function newMedia(Request $request)
  {
    return view('coriumMediaManager::new')->with('pageActive', 'coriumMediaManager')->with('nameTree', 'Media Manager > New')->with('userName', $request->user()->name)->with('email', $request->user()->email);
  }
  public function newMediaSave(Request $request)
  {
    $this->validate($request, [
      'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);
    // echo strlen($request->input('name'));
    if(strlen($request->input('name')) === 0)
    {
      $name = str_random(rand(3,8));
    } else {
      $name = $request->input('name');
    }
    $imageName = str_replace(' ', '', $name .'.'.$request->image->getClientOriginalExtension());
    $request->image->move(public_path('images'). '/' . $request->input('dir'), $imageName);

    
    $files = Storage::allFiles(storage_path('app/public'));
    var_dump($files);
}
}