
======================= 1 =================

The Easiest Way to Create Unique Slugs for Blog Posts in Laravel


Generate a URL friendly "slug" from a given string.


$title = str_slug("Laravel 5 Framework", "-");
// laravel-5-framework



Unique slug

<?php
    public function show($slug)
    {
        $article = Article::where('slug', $slug)->first();
        return view('tutorialspoint.single_post', compact('article'));
    }
?>

And the html code:


<form action="/tutorialspoint/article/store" method="POST">
   {{ csrf_field() }}
   <div class="span12 form-group">
    <label for="title">Article Title</label>
        <input class="span6 form-control" type="text" name="title">
   </div>
   <div class="span12 form-group">
    <label for="body">Article Body</label>
        <textarea class="span6 form-control" name="body" rows="4"></textarea>
    </div>
    <button class="span6 btn btn-success" type="submit">
      Submit
    </button>
</form>


<?php
Route::post('/tutorialspoint/article/store', 'ArticleController@store');
?>


ArticleController, the store() method.


<?php
    public function store()
    {
        try {
            Article::create([
                'title' => request('title'),
                'body' => request('body'),
                'user_id' => auth()->id(),
            ]);

            return redirect("/tutorialspoint/article/create")->with([
                'status' => 'success',
                'message' => 'Your Article was published successfully',
            ]);
        } catch (Exception $e) {
            return redirect("/tutorialspoint/article/create")->with([
                'status' => 'danger',
                'message' => $e->getMessage(),
            ]);
        }
    }
?>

Laravel unique slug First technique

<?php
    public function defineSlugTitle($title_val)
    {
        if (static::whereSlug($gets_slug = str_slug($title_val))->exists()) {
            $gets_slug = $this->incrementSlug($gets_slug);
        }
        $this->attributes['slug'] = $gets_slug;
    }
?>

And the custom incrementSlug() method:

<?php
    public function incrementSlug($slug)
    {
        $title_total = static::whereTitle($this->title)->latest('id')->skip(1)->value('slug');

        if (is_numeric($title_total[-1])) {
            return pred_replace_callback('/(\d+)$/', function ($relavents) {
                return $relavents[1] + 1;
            }, $title_total);
        }

        return "{$slug}-2";
    }
?>

Laravel Second technique

<?php
    public function defineSlugTitle($title_val)
    {
        if (static::whereSlug($gets_slug = str_slug($title_val))->exists()) {
            $gets_slug = "{$gets_slug}-{$this->id}";
        }
        $this->attributes['slug'] = $gets_slug;
    }
?>

=============================== 2 =======================

DropZone Accepted File Formats for Uploads


DropZone acceptedFiles type filter
dropzone.js image upload acceptedMimeTypes


acceptedFiles: ".jpeg,.jpg,.png,.gif",

//all images uploded
acceptedFiles: "image/*",

//Valid acceptedFiles properties 

audio/*
image/*
image/jpeg,
image/png

//acceptedMimeTypes
"audio/*,image/*,.psd,.pdf"

//dropzone.js example with restriction
acceptedFiles: ".png,.jpg,.gif,.bmp,.jpeg",


acceptedFiles: "image/jpeg,image/png,image/gif"

//Documents
pdf, doc, docx, xls, xlsx, csv, txt, rtf, html, zip, 

//Audio & Video
mp3, wma, mpg, flv, avi, 

//Images
jpg, jpeg, png, gif


Type an asterisk * to allow all file types.


Dropzone.options.fileupload = {
  acceptedFiles: "image/jpeg, image/png, image/jpg"
}


maxFiles: 5,
maxFilesize: 20,
acceptedFiles: "image/*,application/pdf,.doc,.docx,.xls,.xlsx,.csv,.tsv,.ppt,.pptx,.pages,.odt,.rtf",


======================================= 3 =================================

