vendredi 6 mars 2020

How to convert the image title to a slug and save it to the Database? Laravel

A user can upload an image and I want to catch the provided $request image title and convert it to a slug and save it to the Database

UploadScreenShotController@upload:

public function upload(Request $request)
{
    if (!auth()->check()) return $this->with('error', 'Session has ended. Please refresh the page and try again.');

    $request->validate([
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);

    $image = $request->image;
    $filename = $image->getClientOriginalName();

    $request->image->move(public_path('images/tcpa/screenshots'), $filename);

    return back()
        ->with('success', 'You have successfully uploaded an image.')
        ->with('image', $filename);
}

My form:

        {!! Form::open(['method' => 'POST', 'files' => 'true', 'route' => ['admin.sms.tcpa-upload-screenshot']])!!}
            {!! Form::file('image') !!}
            {!! Form::submit('Upload File') !!}
        {!! Form::close() !!}

This function gets the image name, but it doesn't convert it to a slug and it doesn't save in the Database.

How to convert the image title to a slug and save it to the Database?



via Chebli Mohamed

1 commentaire:

  1. Use this diet hack to drop 2 lb of fat in just 8 hours

    More than 160,000 women and men are hacking their diet with a simple and SECRET "liquid hack" to drop 2lbs every night while they sleep.

    It is proven and it works on everybody.

    Here's how you can do it yourself:

    1) Take a drinking glass and fill it with water half full

    2) And now do this amazing hack

    you'll become 2lbs skinnier as soon as tomorrow!

    RépondreSupprimer