oxbir

oxbir

Member Since 7 Months Ago

Experience Points
6,770
Total
Experience

3,230 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
6,770 XP
Aug
13
2 days ago
Activity icon

Replied to How To Set Foreach When Saving?

I updated my post

Activity icon

Replied to How To Set Foreach When Saving?

This is essential. Can you answer?

Activity icon

Started a new Conversation How To Set Foreach When Saving?

I want to submit all of them at once no matter the number of fields they add. I am finding it difficult to do that in the controller. I get this error anytime I try submitting the form. And I get this error.

Argument 1 passed to Illuminate\Database\Grammar::parameterize()

This is my code

public function store(Request $request)
{
    $service = new Service;
    $service->user_id = 1;
    $service->title = $request->title;
    $service->lang = $request->lang;
    $service->body = $request->body;
    $service->categories()->attach($request->category);
    $invoice = new Invoice;
    $invoice->price = $request->price;
    $invoice->description = $request->description;
    $invoice->save();
    $service->invoices()->attach($invoice->id);
    return redirect()->route('services.index');
}
Aug
08
1 week ago
Activity icon

Replied to How To Add `slug` To `href`?

Punishes?

Aug
07
1 week ago
Activity icon

Replied to How To Add `slug` To `href`?

@snapey

The real question I said, I want to add slug of houses table to href of categories table.

  • slug => house
  • href => categories

House.php

class House extends Model
{
	use Sluggable;
	/**
	 * Return the sluggable configuration array for this model.
	 *
	 * @return array
	 */
	public function sluggable()
	{
		return [
			'slug' => [
				'source' => 'title'
			]
		];
	}
Activity icon

Started a new Conversation How To Add `slug` To `href`?

Look at my codes, I want to save the information, then everything falls apart.

I have three tables, houses & categories & category_house.

houses & category_house tables

public function up()
{
    Schema::create('houses', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('title');
        $table->string('slug');
        $table->string('lang');
        $table->string('image')->nullable();
        $table->text('sliders');
        $table->text('body');
        $table->timestamps();
    });
    Schema::create('category_house', function (Blueprint $table) {
        $table->bigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->bigInteger('house_id')->unsigned();
        $table->foreign('house_id')->references('id')->on('houses')->onDelete('cascade');
        $table->primary(['category_id' , 'house_id']);
    });
}

categories table

public function up()
{
    Schema::create('categories', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('lang');
        $table->string('href')->nullable();
        $table->integer('parent_id');
        $table->string('icon')->nullable();
        $table->timestamps();
    });
}

edit.blade.php

<form action="{{ route('houses.update', $house->id) }}" method="post">
    @csrf
    @method('PUT')
    <input type="hidden" name="sliders">
    <div class="col-md-6">
        <div class="form-group">
            <label for="title">Title</label>
            <input type="text" class="form-control" id="title" name="title" value="{{ old('title') ?? $house->title }}">
        </div>
    </div>
    <div class="col-md-12">
        <div class="form-group">
            <label for="body">Body</label>
            <textarea class="form-control" id="body" name="body">{{ old('body') ?? $house->body }}</textarea>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group">
            <label for="category">Sub Category</label>
            <select name="category" id="category" class="form-control">
                @foreach($categories as $category)
                    <option value="{{ $category->id }}" {{ $house->categories()->pluck('id')->contains($category->id) ? 'selected' : '' }}>
                        {{ $category->name }}
                    </option>
                @endforeach
            </select>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group">
            <label for="lang">Language</label>
            <select id="lang" name="lang" class="form-control">
                <option value="fa" {{ $house->lang == 'fa' ? 'selected' : '' }}>Farsi</option>
                <option value="en" {{ $house->lang == 'en' ? 'selected' : '' }}>English</option>
            </select>
        </div>
    </div>
    //.....
    <div class="form-group">
        <button class="btn btn-primary btn-lg btn-block">
            <i class="fas fa-check ml-2"></i>Save
        </button>
    </div>
</form>

HouseController.php

 public function update(Request $request, House $house)
{
    $house->user_id = 1;
    $house->title = $request->title;
    $house->lang = $request->lang;
    $house->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $house->image = $request->file('image')->getClientOriginalName();
    }
    $house->save();
    $house->categories()->sync($request->category);
    $category = Category::findOrFail($request->get('category'))->getParent();
    $category->name = $request->title;
    $category->parent_id = $request->category;
    $category->lang = $request->lang;
    $category->href = $request->slug;
    $category->save();
    return redirect()->route('houses.index');
}

Category.php

public function getParent ()
{
    return $this->hasOne(Category::class, 'id', 'parent_id')->withDefault(['name' => '-']);
}

For example, I have the following cateories in database.

id----name-----------------lang------href---------parent_id--------icon-----------------created_at--------updated_at 8-----Main Menu--------en----------NULL------0---------------------fas fa-cube------NULL----------------NULL

The correct method should be stored this way

id----name-----------------lang------href----------------------parent_id--------icon-----------------created_at--------updated_at 8-----Main Menu--------en----------NULL-------------------0---------------------fas fa-cube------NULL----------------NULL 20---Duplex House----en----------duplex-house------8---------------------NULL---------------NULL----------------NULL

But this way it is saved.

id----name-----------------lang------href----------------------parent_id--------icon-----------------created_at--------updated_at 8-----Duplex House----en---------NULL-------------------8---------------------fas fa-cube------NULL----------------NULL 20---Duplex House----en---------NULL-------------------8---------------------NULL---------------NULL----------------NULL

And when I changed this code

$category = Category::findOrFail($request->get('category'))->getParent();

I want to add slug to href.

  • slug => house
  • href => categories
Activity icon

Replied to Too Few Arguments To Function Illuminate\Database\Eloquent\Relations\HasOneOrMany::save

@silencebringer

Thank you, But my problem did not solve yet, I want to add slug to href.

  • slug => house
  • href => categories
Activity icon

Started a new Conversation Too Few Arguments To Function Illuminate\Database\Eloquent\Relations\HasOneOrMany::save

Look at my codes, I want to save the information, then everything falls apart.

I have three tables, houses & categories & category_house.

houses & category_house tables

public function up()
{
    Schema::create('houses', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('title');
        $table->string('slug');
        $table->string('lang');
        $table->string('image')->nullable();
        $table->text('sliders');
        $table->text('body');
        $table->timestamps();
    });
    Schema::create('category_house', function (Blueprint $table) {
        $table->bigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->bigInteger('house_id')->unsigned();
        $table->foreign('house_id')->references('id')->on('houses')->onDelete('cascade');
        $table->primary(['category_id' , 'house_id']);
    });
}

categories table

public function up()
{
    Schema::create('categories', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('lang');
        $table->string('href')->nullable();
        $table->integer('parent_id');
        $table->string('icon')->nullable();
        $table->timestamps();
    });
}

edit.blade.php

<form action="{{ route('houses.update', $house->id) }}" method="post">
    @csrf
    @method('PUT')
    <input type="hidden" name="sliders">
    <div class="col-md-6">
        <div class="form-group">
            <label for="title">Title</label>
            <input type="text" class="form-control" id="title" name="title" value="{{ old('title') ?? $house->title }}">
        </div>
    </div>
    <div class="col-md-12">
        <div class="form-group">
            <label for="body">Body</label>
            <textarea class="form-control" id="body" name="body">{{ old('body') ?? $house->body }}</textarea>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group">
            <label for="category">Sub Category</label>
            <select name="category" id="category" class="form-control">
                @foreach($categories as $category)
                    <option value="{{ $category->id }}" {{ $house->categories()->pluck('id')->contains($category->id) ? 'selected' : '' }}>
                        {{ $category->name }}
                    </option>
                @endforeach
            </select>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group">
            <label for="lang">Language</label>
            <select id="lang" name="lang" class="form-control">
                <option value="fa" {{ $house->lang == 'fa' ? 'selected' : '' }}>Farsi</option>
                <option value="en" {{ $house->lang == 'en' ? 'selected' : '' }}>English</option>
            </select>
        </div>
    </div>
    //.....
    <div class="form-group">
        <button class="btn btn-primary btn-lg btn-block">
            <i class="fas fa-check ml-2"></i>Save
        </button>
    </div>
</form>

HouseController.php

 public function update(Request $request, House $house)
{
    $house->user_id = 1;
    $house->title = $request->title;
    $house->lang = $request->lang;
    $house->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $house->image = $request->file('image')->getClientOriginalName();
    }
    $house->save();
    $house->categories()->sync($request->category);
    $category = Category::findOrFail($request->get('category'))->getParent();
    $category->name = $request->title;
    $category->parent_id = $request->category;
    $category->lang = $request->lang;
    $category->href = $request->slug;
    $category->save();
    return redirect()->route('houses.index');
}

Category.php

public function getParent ()
{
    return $this->hasOne(Category::class, 'id', 'parent_id')->withDefault(['name' => '-']);
}

For example, I have the following cateories in database.

id----name-----------------lang------href---------parent_id--------icon-----------------created_at--------updated_at 8-----Main Menu--------en----------NULL------0---------------------fas fa-cube------NULL----------------NULL

The correct method should be stored this way

id----name-----------------lang------href----------------------parent_id--------icon-----------------created_at--------updated_at 8-----Main Menu--------en----------NULL-------------------0---------------------fas fa-cube------NULL----------------NULL 20---Duplex House----en----------duplex-house------8---------------------NULL---------------NULL----------------NULL

But this way it is saved.

id----name-----------------lang------href----------------------parent_id--------icon-----------------created_at--------updated_at 8-----Duplex House----en---------NULL-------------------8---------------------fas fa-cube------NULL----------------NULL 20---Duplex House----en---------NULL-------------------8---------------------NULL---------------NULL----------------NULL

And when I changed this code

$category = Category::findOrFail($request->get('category'))->getParent();

I get this error

update

Aug
06
1 week ago
Activity icon

Replied to Admin Dashboard Template Built On Tailwind CSS

Does it work with rtl?

Activity icon

Replied to How To Find Category Of Photographers When I Editted In Laravel

Hi @silencebringer

It display null. This is a surprise to me.

Activity icon

Started a new Conversation How To Find Category Of Photographers When I Editted In Laravel

I am creating a blog in Laravel. I have two tables - photographers and categories. When i want to edit one photographer, I have a problem with categories. My photographer controller is sending categories to the view, I can see them while editing.

When added the photographers table:

public function store(Request $request)
{
    $photographer = new Photographer;
    $photographer->user_id = 1;
    $photographer->title = $request->title;
    $photographer->lang = $request->lang;
    $photographer->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $photographer->image = $request->file('image')->getClientOriginalName();
    }
    $photographer->sliders = json_decode($request->sliders, true);
    $photographer->save();
    $photographer->categories()->attach($request->category);
    $category = new Category;
    $category->name = $request->title;
    $category->parent_id = $request->category;
    $category->lang = $request->lang;
    $category->save();
    return redirect()->route('photographers.index');
}

When update

public function update(Request $request, Photographer $photographer)
{
    $photographer->user_id = 1;
    $photographer->title = $request->title;
    $photographer->lang = $request->lang;
    $photographer->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $photographer->image = $request->file('image')->getClientOriginalName();
    }
    $photographer->sliders = json_decode($request->sliders, true);
    $photographer->save();
    $photographer->categories()->sync($request->category);
    $category = Category::find($request->get('id'));
    $category->name = $request->title;
    $category->parent_id = $request->category;
    $category->lang = $request->lang;
    $category->save();
    return redirect()->route('photographers.index');
}

Photographer.php

public function categories()
{
    return $this->belongsToMany(Category::class);
}

I get this error.

Creating default object from empty value

When I changed after

$category = Category::find($request->get('id'));
dd($category);

I see display null.

Activity icon

Replied to How To Find Category When I Updated

When I changed after

 $category = Category::find($request->get('id'));
dd($category);

I see display null.

Aug
05
1 week ago
Activity icon

Replied to How To Find Category When I Updated

I get this error.

Creating default object from empty value

Activity icon

Started a new Conversation How To Find Category When I Updated

I am creating a blog in Laravel. I have two tables - photographers and categories. When i want to edit one photographer, I have a problem with categories. My photographer controller is sending categories to the view, I can see them while editing.

When added the photographers table:

public function store(Request $request)
{
    $photographer = new Photographer;
    $photographer->user_id = 1;
    $photographer->title = $request->title;
    $photographer->lang = $request->lang;
    $photographer->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $photographer->image = $request->file('image')->getClientOriginalName();
    }
    $photographer->sliders = json_decode($request->sliders, true);
    $photographer->save();
    $photographer->categories()->attach($request->category);
    $category = new Category;
    $category->name = $request->title;
    $category->parent_id = $request->category;
    $category->lang = $request->lang;
    $category->save();
    return redirect()->route('photographers.index');
}

When update

public function update(Request $request, Photographer $photographer)
{
    $photographer->user_id = 1;
    $photographer->title = $request->title;
    $photographer->lang = $request->lang;
    $photographer->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $photographer->image = $request->file('image')->getClientOriginalName();
    }
    $photographer->sliders = json_decode($request->sliders, true);
    $photographer->save();
    $photographer->categories()->sync($request->category);
    $category = Category::find($request->get('id'));
    $category->name = $request->title;
    $category->parent_id = $request->category;
    $category->lang = $request->lang;
    $category->save();
    return redirect()->route('photographers.index');
}

Photographer.php

public function categories()
{
    return $this->belongsToMany(Category::class);
}
Aug
03
1 week ago
Activity icon

Replied to How To Merge All Models In Laravel

@michaloravec

Can you send complete code?

Because I tried in 2 days.My problem did not solve yet.

Aug
02
1 week ago
Activity icon

Replied to How To Merge All Models In Laravel

I get this error .

Call to undefined method Faker\Provider\Image::has()

Activity icon

Started a new Conversation How To Merge All Models In Laravel

I want to show all slideshow when the images are not blank.

public function index()
{
    $slideAdvertise = Advertise::whereNotNull('image')->get();
    $slideDesignStudio = DesignStudio::whereNotNull('image')->get();
    $slideHouse = House::whereNotNull('image')->get();
    $slidePhotographer = Photographer::whereNotNull('image')->get();
    $slideWebsite = Website::whereNotNull('image')->get();
    $slideShows = $slideAdvertise->merge($slideDesignStudio)->merge($slideHouse)->merge($slidePhotographer)->merge($slideWebsite);
    return view('Home.index', compact('slideShows'));
}
Aug
01
2 weeks ago
Activity icon

Started a new Conversation Argument 1 Passed To Illuminate\Database\Grammar::parameterize() Must Be Of The Type Array, String Given, Called In C:\xampp\htdocs\tehran\khaneyeax\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php On Line 869

I have three tables.

  • galleries
  • design_studios
  • design_studio_gallery

galleries

public function up()
{
    Schema::create('galleries', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('caption');
        $table->string('picture');
        $table->text('description');
        $table->timestamps();
    });
}

design_studios

public function up()
{
    Schema::create('design_studios', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('title');
        $table->string('slug');
        $table->string('lang');
        $table->string('image')->nullable();
        $table->text('sliders');
        $table->text('body');
        $table->timestamps();
    });
    Schema::create('category_design_studio', function (Blueprint $table) {
        $table->bigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->bigInteger('design_studio_id')->unsigned();
        $table->foreign('design_studio_id')->references('id')->on('design_studios')->onDelete('cascade');
        $table->primary(['category_id' , 'design_studio_id']);
    });
    Schema::create('gallery_design_studio', function (Blueprint $table) {
        $table->bigInteger('gallery_id')->unsigned();
        $table->foreign('gallery_id')->references('id')->on('galleries')->onDelete('cascade');
        $table->bigInteger('design_studio_id')->unsigned();
        $table->foreign('design_studio_id')->references('id')->on('design_studios')->onDelete('cascade');
        $table->primary(['gallery_id' , 'design_studio_id']);
    });
}

I want to create multiple gallery with dynamic.

My blade

@extends('Admin.master')

@section('style')
    <link rel="stylesheet" href="{{ asset('themes/css/dropzone.css') }}">
@endsection

@section('content')

    <h3><i class="fas fa-plus-square ml-2"></i>افزودن استدیو طراحی جدید</h3><hr>
    @include('Admin.layouts.errors')

    <form action="{{ route('design-studios.store') }}" method="post" enctype="multipart/form-data" id="form">
        @csrf
        <input type="hidden" name="sliders">
        <div class="col-md-6">
            <div class="form-group">
                <label for="title">عنوان</label>
                <input type="text" class="form-control" id="title" name="title" value="{{ old('title') }}">
            </div>
        </div>
        <div class="form-group">
            <label for="body">متن</label>
            <textarea class="form-control" id="body" name="body"></textarea>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="category">دسته بندی</label>
                    <select name="category" id="category" class="form-control">
                        @foreach($categories as $category)
                            <option value="{{ $category->id }}">{{ $category->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="lang">زبان</label>
                    <select id="lang" name="lang" class="form-control">
                        <option value="fa">فارسی</option>
                        <option value="en">انگلیسی</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <fieldset class="border p-3">
                <legend>اسلایدر</legend>
                <div class="dropzone" id="drop">

                </div>
            </fieldset>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label for="image">تصویر</label>
                <input id="image" name="image" type="file" class="form-control">
                <small>این تصویر برای اسلایدشو در صفحه اصلی میباشد.</small>
            </div>
        </div>
        <div class="form-group">
            <fieldset class="border p-3">
                <legend>گالری</legend>
                <div class="row border-danger" id="showGallery">

                </div>
                <div class="row mb-2 bg-white mb-5">
                    <div class="w-100 text-center">
                        <p>گالری دیگری را اضافه کنید.</p>
                        <a id="addGallery" class="bg-primary text-white pt-2 pb-2 pl-3 pr-3 rounded-circle cursor-pointer">
                            <i class="fas fa-plus"></i>
                        </a>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="form-group">
            <button class="btn btn-primary btn-lg btn-block">
                <i class="fas fa-check ml-2"></i>دخیره
            </button>
        </div>
    </form>

@endsection

@section('script')

    <script src="{{ asset('themes/js/dropzone.js') }}"></script>
    <script src="{{ asset('themes/ckeditor/ckeditor.js') }}"></script>
    <script>
        let sliders = [];
        Dropzone.autoDiscover = false;
        $(document).ready(function(){
            $('#drop').dropzone({
                url: '{{ route('design-studios.dropzone') }}',
                method: 'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(f, r) {
                    let {slider} = r;
                    if(slider)
                        sliders.push(slider);
                    $('input[name="sliders"]').val(JSON.stringify(sliders));
                },
            });
        });

        CKEDITOR.replace('body', {
            filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
            filebrowserUploadMethod: 'form',
            extraPlugins: 'easyimage',
            cloudServices_tokenUrl: 'http://localhost:8000/admin/ckeditor/image-upload',
            cloudServices_uploadUrl: 'http://localhost:8000/admin/ckeditor/image-upload'
        });

        let countGallery = 1;

        $('#addGallery').click(function () {
            countGallery++;
            dynamicGallery(countGallery);
        });

        dynamicGallery(countGallery);

        function dynamicGallery (number) {
            let html = '' +
                '<div class="col-md-6">\n' +
                '<div class="form-group">\n' +
                '<label for="caption">عنوان گالری</label>\n' +
                '<input type="text" id="caption" name="caption[]" class="form-control">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label for="description">متن گالری</label>\n' +
                '<textarea type="text" id="description" name="description[]" class="form-control"></textarea>\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label for="picture">تصویر گالری</label>\n' +
                '<input type="file" id="picture" name="picture[]" class="form-control">\n' +
                '</div>\n' +
                '</div>';
            $('#showGallery').append(html);
        }

        $('body').on('click','label', function (e) {
            e.preventDefault();
            $(this).next().focus();
        });
    </script>
@endsection

Controller

    public function store(Request $request)
    {
        $designStudio = new DesignStudio;
        $designStudio->user_id = 1;
        $designStudio->title = $request->title;
        $designStudio->lang = $request->lang;
        $designStudio->body = $request->body;
        if($request->has('image')) {
            $image = $request->file('image');
            $filename = $image->getClientOriginalName();
            $image->move(public_path('images/slideShows'), $filename);
            $designStudio->image = $request->file('image')->getClientOriginalName();
        }
        $designStudio->sliders = json_decode($request->sliders, true);
        $designStudio->save();
        $designStudio->categories()->attach($request->category);
        $gallery = new Gallery();
        $gallery->caption = $request->caption;
        if($request->has('picture')) {
            foreach ($request->picture as $picture) {
                $randomize = rand(111111, 999999);
                $extension = $picture->extension();
                $filename = $randomize . '.' . $extension;
                $picture->move(public_path('images/galleries/'), $filename);
                $data[] = $filename;
            }
        }
        $gallery->picture = $data;
        $gallery->description = $request->description;
        $gallery->save();
        $designStudio->galleries()->attach($gallery->id);
        return redirect()->route('design-studios.index');
    }

I get this error

Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in C:\xampp\htdocs\tehran\khaneyeax\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 869

Jul
31
2 weeks ago
Activity icon

Replied to SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'flower Group' For Column 'gallery_id' At Row 1 (SQL: Insert Into Design_studio_gallery (design_studio_id, Gallery_id) Values (6, Flower 2), (6, Flower 1))

@marianomoreyra ,

Ok, I changed this code

public function store(Request $request)
{
    $designStudio = new DesignStudio;
    $designStudio->user_id = 1;
    $designStudio->title = $request->title;
    $designStudio->lang = $request->lang;
    $designStudio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $designStudio->image = $request->file('image')->getClientOriginalName();
    }
    $designStudio->sliders = json_decode($request->sliders, true);
    $designStudio->save();
    $gallery = new Gallery();
    $gallery->caption = $request->caption;
    if($request->has('picture')) {
        $picture = $request->file('picture');
        $filename = $picture->getClientOriginalName();
        $picture->move(public_path('images/galleries'), $filename);
        $gallery->picture = $request->file('picture')->getClientOriginalName();
    }
    $gallery->description = $request->description;
    $gallery->save();
    $designStudio->galleries()->attach($gallery->id);
    return redirect()->route('design-studios.index');
}

But I get this error

Call to a member function getClientOriginalName() on array

error

Activity icon

Replied to SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'flower Group' For Column 'gallery_id' At Row 1 (SQL: Insert Into Design_studio_gallery (design_studio_id, Gallery_id) Values (6, Flower 2), (6, Flower 1))

I tried and changed this code

public function store(Request $request)
{
    $designStudio = new DesignStudio;
    $designStudio->user_id = 1;
    $designStudio->title = $request->title;
    $designStudio->lang = $request->lang;
    $designStudio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $designStudio->image = $request->file('image')->getClientOriginalName();
    }
    $designStudio->sliders = json_decode($request->sliders, true);
    $designStudio->save();
    $gallery = new Gallery();
    $gallery->caption = $request->caption;
    if($pictures = $request->has('picture')) {
        foreach ($pictures as $picture) {
            $randomize = rand(111111, 999999);
            $extension = $gallery->extension();
            $filename = $randomize . '.' . $extension;
            $gallery->move(public_path('images/galleries/'), $filename);
            $data[] = $filename;
        }
    }
    $gallery->description = $request->description;
    $gallery->save();
    $designStudio->galleries()->attach($gallery->id);
    return redirect()->route('design-studios.index');
}

But I see this error.

Invalid argument supplied for foreach()

error

Activity icon

Started a new Conversation SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'flower Group' For Column 'gallery_id' At Row 1 (SQL: Insert Into Design_studio_gallery (design_studio_id, Gallery_id) Values (6, Flower 2), (6, Flower 1))

I have three tables.

  • galleries
  • design_studios
  • design_studio_gallery

galleries

public function up()
{
    Schema::create('galleries', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('caption');
        $table->string('picture');
        $table->text('description');
        $table->timestamps();
    });
}

design_studios

public function up()
{
    Schema::create('design_studios', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('title');
        $table->string('slug');
        $table->string('lang');
        $table->string('image')->nullable();
        $table->text('sliders');
        $table->text('body');
        $table->timestamps();
    });
    Schema::create('category_design_studio', function (Blueprint $table) {
        $table->bigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->bigInteger('design_studio_id')->unsigned();
        $table->foreign('design_studio_id')->references('id')->on('design_studios')->onDelete('cascade');
        $table->primary(['category_id' , 'design_studio_id']);
    });
    Schema::create('gallery_design_studio', function (Blueprint $table) {
        $table->bigInteger('gallery_id')->unsigned();
        $table->foreign('gallery_id')->references('id')->on('galleries')->onDelete('cascade');
        $table->bigInteger('design_studio_id')->unsigned();
        $table->foreign('design_studio_id')->references('id')->on('design_studios')->onDelete('cascade');
        $table->primary(['gallery_id' , 'design_studio_id']);
    });
}

I want to create multiple gallery with dynamic.

My blade

@extends('Admin.master')

@section('style')
    <link rel="stylesheet" href="{{ asset('themes/css/dropzone.css') }}">
@endsection

@section('content')

    <h3><i class="fas fa-plus-square ml-2"></i>افزودن استدیو طراحی جدید</h3><hr>
    @include('Admin.layouts.errors')

    <form action="{{ route('design-studios.store') }}" method="post" enctype="multipart/form-data" id="form">
        @csrf
        <input type="hidden" name="sliders">
        <div class="col-md-6">
            <div class="form-group">
                <label for="title">عنوان</label>
                <input type="text" class="form-control" id="title" name="title" value="{{ old('title') }}">
            </div>
        </div>
        <div class="form-group">
            <label for="body">متن</label>
            <textarea class="form-control" id="body" name="body"></textarea>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="category">دسته بندی</label>
                    <select name="category" id="category" class="form-control">
                        @foreach($categories as $category)
                            <option value="{{ $category->id }}">{{ $category->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="lang">زبان</label>
                    <select id="lang" name="lang" class="form-control">
                        <option value="fa">فارسی</option>
                        <option value="en">انگلیسی</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <fieldset class="border p-3">
                <legend>اسلایدر</legend>
                <div class="dropzone" id="drop">

                </div>
            </fieldset>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label for="image">تصویر</label>
                <input id="image" name="image" type="file" class="form-control">
                <small>این تصویر برای اسلایدشو در صفحه اصلی میباشد.</small>
            </div>
        </div>
        <div class="form-group">
            <fieldset class="border p-3">
                <legend>گالری</legend>
                <div class="row border-danger" id="showGallery">

                </div>
                <div class="row mb-2 bg-white mb-5">
                    <div class="w-100 text-center">
                        <p>گالری دیگری را اضافه کنید.</p>
                        <a id="addGallery" class="bg-primary text-white pt-2 pb-2 pl-3 pr-3 rounded-circle cursor-pointer">
                            <i class="fas fa-plus"></i>
                        </a>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="form-group">
            <button class="btn btn-primary btn-lg btn-block">
                <i class="fas fa-check ml-2"></i>دخیره
            </button>
        </div>
    </form>

@endsection

@section('script')

    <script src="{{ asset('themes/js/dropzone.js') }}"></script>
    <script src="{{ asset('themes/ckeditor/ckeditor.js') }}"></script>
    <script>
        let sliders = [];
        Dropzone.autoDiscover = false;
        $(document).ready(function(){
            $('#drop').dropzone({
                url: '{{ route('dropzone') }}',
                method: 'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(f, r) {
                    let {slider} = r;
                    if(slider)
                        sliders.push(slider);
                    $('input[name="sliders"]').val(JSON.stringify(sliders));
                },
            });
        });

        CKEDITOR.replace('body', {
            filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
            filebrowserUploadMethod: 'form',
            extraPlugins: 'easyimage',
            cloudServices_tokenUrl: 'http://localhost:8000/admin/ckeditor/image-upload',
            cloudServices_uploadUrl: 'http://localhost:8000/admin/ckeditor/image-upload'
        });

        let countGallery = 1;

        $('#addGallery').click(function () {
            countGallery++;
            dynamicGallery(countGallery);
        });

        dynamicGallery(countGallery);

        function dynamicGallery (number) {
            let html = '' +
                '<div class="col-md-6">\n' +
                '<div class="form-group">\n' +
                '<label for="caption">عنوان گالری</label>\n' +
                '<input type="text" id="caption" name="caption[]" class="form-control">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label for="description">متن گالری</label>\n' +
                '<textarea type="text" id="description" name="description[]" class="form-control"></textarea>\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label for="picture">تصویر گالری</label>\n' +
                '<input type="file" id="picture" name="picture[]" class="form-control">\n' +
                '</div>\n' +
                '</div>';
            $('#showGallery').append(html);
        }

        $('body').on('click','label', function (e) {
            e.preventDefault();
            $(this).next().focus();
        });
    </script>
@endsection

DesignStudioController.php

public function store(Request $request)
{
    $designStudio = new DesignStudio;
    $designStudio->user_id = 1;
    $designStudio->title = $request->title;
    $designStudio->lang = $request->lang;
    $designStudio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $designStudio->image = $request->file('image')->getClientOriginalName();
    }
    $designStudio->sliders = json_decode($request->sliders, true);
    $designStudio->save();
    $designStudio->categories()->attach($request->category);
    $designStudio->galleries()->attach($request->caption);
    $designStudio->galleries()->attach($request->description);
    $designStudio->galleries()->attach($request->picture);
    return redirect()->route('design-studios.index');
}

I get this error.

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'flower group' for column 'gallery_id' at row 1 (SQL: insert into design_studio_gallery (design_studio_id, gallery_id) values (6, flower 2), (6, flower 1))

Activity icon

Replied to SQLSTATE[42S02]: Base Table Or View Not Found: 1146 Table 'khaneyeax.design_studio_gallery' Doesn't Exist (SQL: Insert Into `design_studio_gallery` (`design_studio_id`, `gallery_id`) Values (4, Flower 1), (4, Flower 2))

Hello @marianomoreyra

I get this error

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'flower group' for column 'gallery_id' at row 1 (SQL: insert into design_studio_gallery (design_studio_id, gallery_id) values (6, flower 2), (6, flower 1))

Activity icon

Started a new Conversation SQLSTATE[42S02]: Base Table Or View Not Found: 1146 Table 'khaneyeax.design_studio_gallery' Doesn't Exist (SQL: Insert Into `design_studio_gallery` (`design_studio_id`, `gallery_id`) Values (4, Flower 1), (4, Flower 2))

I have three tables.

  • galleries
  • design_studios
  • design_studio_gallery

galleries

public function up()
{
    Schema::create('galleries', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('caption');
        $table->string('picture');
        $table->text('description');
        $table->timestamps();
    });
}

design_studios

public function up()
{
    Schema::create('design_studios', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->string('title');
        $table->string('slug');
        $table->string('lang');
        $table->string('image')->nullable();
        $table->text('sliders');
        $table->text('body');
        $table->timestamps();
    });
    Schema::create('category_design_studio', function (Blueprint $table) {
        $table->bigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->bigInteger('design_studio_id')->unsigned();
        $table->foreign('design_studio_id')->references('id')->on('design_studios')->onDelete('cascade');
        $table->primary(['category_id' , 'design_studio_id']);
    });
    Schema::create('gallery_design_studio', function (Blueprint $table) {
        $table->bigInteger('gallery_id')->unsigned();
        $table->foreign('gallery_id')->references('id')->on('galleries')->onDelete('cascade');
        $table->bigInteger('design_studio_id')->unsigned();
        $table->foreign('design_studio_id')->references('id')->on('design_studios')->onDelete('cascade');
        $table->primary(['gallery_id' , 'design_studio_id']);
    });
}

I want to create multiple gallery with dynamic.

My blade

@extends('Admin.master')

@section('style')
    <link rel="stylesheet" href="{{ asset('themes/css/dropzone.css') }}">
@endsection

@section('content')

    <h3><i class="fas fa-plus-square ml-2"></i>افزودن استدیو طراحی جدید</h3><hr>
    @include('Admin.layouts.errors')

    <form action="{{ route('design-studios.store') }}" method="post" enctype="multipart/form-data" id="form">
        @csrf
        <input type="hidden" name="sliders">
        <div class="col-md-6">
            <div class="form-group">
                <label for="title">عنوان</label>
                <input type="text" class="form-control" id="title" name="title" value="{{ old('title') }}">
            </div>
        </div>
        <div class="form-group">
            <label for="body">متن</label>
            <textarea class="form-control" id="body" name="body"></textarea>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="category">دسته بندی</label>
                    <select name="category" id="category" class="form-control">
                        @foreach($categories as $category)
                            <option value="{{ $category->id }}">{{ $category->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="lang">زبان</label>
                    <select id="lang" name="lang" class="form-control">
                        <option value="fa">فارسی</option>
                        <option value="en">انگلیسی</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <fieldset class="border p-3">
                <legend>اسلایدر</legend>
                <div class="dropzone" id="drop">

                </div>
            </fieldset>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label for="image">تصویر</label>
                <input id="image" name="image" type="file" class="form-control">
                <small>این تصویر برای اسلایدشو در صفحه اصلی میباشد.</small>
            </div>
        </div>
        <div class="form-group">
            <fieldset class="border p-3">
                <legend>گالری</legend>
                <div class="row border-danger" id="showGallery">

                </div>
                <div class="row mb-2 bg-white mb-5">
                    <div class="w-100 text-center">
                        <p>گالری دیگری را اضافه کنید.</p>
                        <a id="addGallery" class="bg-primary text-white pt-2 pb-2 pl-3 pr-3 rounded-circle cursor-pointer">
                            <i class="fas fa-plus"></i>
                        </a>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="form-group">
            <button class="btn btn-primary btn-lg btn-block">
                <i class="fas fa-check ml-2"></i>دخیره
            </button>
        </div>
    </form>

@endsection

@section('script')

    <script src="{{ asset('themes/js/dropzone.js') }}"></script>
    <script src="{{ asset('themes/ckeditor/ckeditor.js') }}"></script>
    <script>
        let sliders = [];
        Dropzone.autoDiscover = false;
        $(document).ready(function(){
            $('#drop').dropzone({
                url: '{{ route('dropzone') }}',
                method: 'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(f, r) {
                    let {slider} = r;
                    if(slider)
                        sliders.push(slider);
                    $('input[name="sliders"]').val(JSON.stringify(sliders));
                },
            });
        });

        CKEDITOR.replace('body', {
            filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
            filebrowserUploadMethod: 'form',
            extraPlugins: 'easyimage',
            cloudServices_tokenUrl: 'http://localhost:8000/admin/ckeditor/image-upload',
            cloudServices_uploadUrl: 'http://localhost:8000/admin/ckeditor/image-upload'
        });

        let countGallery = 1;

        $('#addGallery').click(function () {
            countGallery++;
            dynamicGallery(countGallery);
        });

        dynamicGallery(countGallery);

        function dynamicGallery (number) {
            let html = '' +
                '<div class="col-md-6">\n' +
                '<div class="form-group">\n' +
                '<label for="caption">عنوان گالری</label>\n' +
                '<input type="text" id="caption" name="caption[]" class="form-control">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label for="description">متن گالری</label>\n' +
                '<textarea type="text" id="description" name="description[]" class="form-control"></textarea>\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label for="picture">تصویر گالری</label>\n' +
                '<input type="file" id="picture" name="picture[]" class="form-control">\n' +
                '</div>\n' +
                '</div>';
            $('#showGallery').append(html);
        }

        $('body').on('click','label', function (e) {
            e.preventDefault();
            $(this).next().focus();
        });
    </script>
@endsection

DesignStudioController.php

public function store(Request $request)
{
    $designStudio = new DesignStudio;
    $designStudio->user_id = 1;
    $designStudio->title = $request->title;
    $designStudio->lang = $request->lang;
    $designStudio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShows'), $filename);
        $designStudio->image = $request->file('image')->getClientOriginalName();
    }
    $designStudio->sliders = json_decode($request->sliders, true);
    $designStudio->save();
    $designStudio->categories()->attach($request->category);
    $designStudio->galleries()->attach($request->caption);
    $designStudio->galleries()->attach($request->description);
    $designStudio->galleries()->attach($request->picture);
    return redirect()->route('design-studios.index');
}
Jul
30
2 weeks ago
Activity icon

Started a new Conversation The POST Method Is Not Supported For This Route. Supported Methods: GET, HEAD.

When I upload an image with ckeditor. I get this error.

ckeditor

edit.blade.php

CKEDITOR.replace('body', {
    filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
    filebrowserUploadMethod: 'form',
    extraPlugins: 'easyimage',
    cloudServices_tokenUrl: 'http://localhost:8000/admin/ckeditor/image-upload',
    cloudServices_uploadUrl: 'http://localhost:8000/admin/ckeditor/image-upload'
});

web.php

Route::namespace('Admin')->prefix('admin')->group(function (){ Route::get('dashboard', '[email protected]')->name('dashboard.index'); Route::get('ckeditor/image-upload', '[email protected]')->name('upload');

DashboardController.php

public function upload(Request $request)
{
    $this->validate(request() , [
        'upload' => 'required|mimes:jpeg,png,bmp',
    ]);

    $year = Carbon::now()->year;
    $imagePath = "public/upload/images/{$year}/";

    $file = request()->file('upload');
    $filename = $file->getClientOriginalName();

    if(file_exists(public_path($imagePath) . $filename)) {
        $filename = Carbon::now()->timestamp . $filename;
    }

    $file->move(public_path($imagePath) , $filename);
    $url = $imagePath . $filename;

    return "<script>window.parent.CKEDITOR.tools.callFunction(1 , '{$url}' , '')</script>";
}
Jul
29
2 weeks ago
Activity icon

Replied to How To Change The Best Code?

@tray2

I see this sliders field in database [] and it did not copied to images/design-studios folders.

Jul
28
2 weeks ago
Activity icon

Started a new Conversation How To Change The Best Code?

I downloaded a package my friend. The coding of this package is not suitable in my opinion. I want to rename to rand(11111111,99999999).

default package

public function dropzone(Request $request)
{
    if($request->hasFile('file') && $slider = $request->file('file')) {
        return response([
            'slider'=> \Storage::disk('custom')
                ->put('images/design-studios', $slider, 'public'),
        ]);
    }
}

rename

public function dropzone(Request $request)
{
    $randomize = rand(1111111, 9999999);
    if($request->hasFile('file') && $slider = $request->file('file')) {
        return response([
            'slider'=> move_uploaded_file($randomize, public_path('images/design-studios')),
        ]);
    }
}
Activity icon

Started a new Conversation Undefined Variable: Data

I want to upload multiple image with dropzone but I get this error.

public function dropzone(Request $request)
{
    if ($sliders = $request->file('sliders')) {
        foreach ($sliders as $slider) {
            $randomize = rand(1111111111, 9999999999);
            $extension = $slider->extension();
            $filename = $randomize . '.' . $extension;
            $slider->move(public_path('images/design-studios/'), $filename);
            $data[] = $filename;
        }
    }
    return $slider->sliders = $data;
}

I get this error.

data

Activity icon

Replied to Dropzone CSRF Token Mismatch

I replaced it

<script src="{{ asset('themes/js/dropzone.js') }}"></script>
<script>
    Dropzone.autoDiscover = false;
    $(document).ready(function(){
        $('#drop').dropzone({
            url: '{{ route('dropzone') }}',
            method: 'post',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="token"]').attr('content')
            }
        });
    });
</script>

But my problem did not solve yet. I get this error again.

dropzone

Jul
27
2 weeks ago
Activity icon

Started a new Conversation Dropzone CSRF Token Mismatch

I am using Dropzone to upload images using Laravel 5. After Dropzone makes the put call to my URL I get the following error:

dropzone

upload.blade.php

<div class="dropzone" id="drop">

</div>

header

@section('style')
    <link rel="stylesheet" href="{{ asset('themes/css/dropzone.css') }}">
@endsection

script.js

<script src="{{ asset('themes/js/dropzone.js') }}"></script>
<script>
    Dropzone.autoDiscover = false;
    $(document).ready(function(){
        $('#drop').dropzone({
            url: '{{ route('dropzone') }}',
            method: 'post'
        });
    });
</script>
Activity icon

Started a new Conversation Invalid Argument Supplied For Foreach() In Lravel 5.8

I save sliders with json_encode.

if ($sliders = $request->file('sliders')) {
    foreach ($sliders as $slider) {
        $filename = rand(111111, 999999);
        $extension = $slider->extension();
        $getFileExt = $filename . '.' . $extension;
        $slider->move(public_path('images/design-studios/'), $getFileExt);
        $data[] = $getFileExt;
    }
}
$design_studio->sliders = json_encode($data);
$design_studio->save();

And in model

protected $casts = [
    'sliders' => 'array'
];

And I want to show sliders in my page

<div class="row">
    @foreach($designStudio->sliders as $slider)
        <div class="col-md-3">
            <img src="{{ asset('images/design-studios/'.$slider) }}" class="img-fluid">
        </div>
    @endforeach
</div>

But I get this error.

error

The sliders saved like this.

"[\"569467.jpeg\",\"630883.png\",\"198204.png\",\"439370.png\"]"

My controller when I save sliders

    if ($sliders = $request->file('sliders')) {
        foreach ($sliders as $slider) {
            $filename = rand(111111, 999999);
            $extension = $slider->extension();
            $getFileExt = $filename . '.' . $extension;
            $slider->move(public_path('images/design-studios/'), $getFileExt);
            $data[] = $getFileExt;
        }
    }
    $design_studio->sliders = json_encode($data);
    $design_studio->save();
Activity icon

Started a new Conversation SQLSTATE[HY000]: General Error: 1364 Field 'sliders' Doesn't Have A Default Value

I have a multiple image. When I upload multiple image. I get this error.

SQLSTATE[HY000]: General error: 1364 Field 'sliders' doesn't have a default value

my blade

<form action="{{ route('design-studios.store') }}" method="post" enctype="multipart/form-data">
    @csrf
    <div class="form-group">
        <label for="title">Title</label>
        <input type="text" class="form-control" id="title" name="title" value="{{ old('title') }}">
    </div>
   //......
    <div class="form-group">
        <fieldset class="border p-3">
            <legend>Slideshow</legend>
            <div class="form-group">
                <label for="sliders">Image</label>
                <input id="sliders" name="sliders[]" type="file" multiple class="form-control">
            </div>
        </fieldset>
    </div>
</form>

My Controller.

public function store(Request $request)
{
    $design_studio = new DesignStudio;
    $design_studio->user_id = 1;
    $design_studio->title = $request->title;
    $design_studio->lang = $request->lang;
    $design_studio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/design-studio'), $filename);
        $design_studio->image = $request->file('image')->getClientOriginalName();
    }
    if ($sliders = $request->file('sliders')) {
        foreach ($sliders as $slider) {
            $filename = rand(111111, 999999);
            $extension = $slider->extension();
            $getFileExt = $filename . '.' . $extension;
            $slider->move(public_path('images/design-studios/'), $getFileExt);
        }
    }
    $design_studio->save();
    $design_studio->categories()->attach($request->category);
    return redirect()->route('design-studios.index');
}

My Model

protected $casts = [
    'sliders' => 'array'
];

I get this error.

error

Activity icon

Started a new Conversation How To Select Default Option To When Edit

I want to select id of option in select option/

Look at my codes...

ArticleController

public function edit(Article $article)
{
    $categories = Category::all();
    return view('Admin.articles.edit', compact('categories', 'article'));
}

Article.php

public function categories()
{
    return $this->belongsToMany(Category::class);
}

edit.blade.php

<select name="category" id="category" class="form-control">
    @foreach($categories as $category)
        <option value="{{ $category->id }}" {{ $category->id == $category->id ? 'selected' : '' }}>
            {{ $category->name_fa }}
        </option>
    @endforeach
</select>
Jul
26
2 weeks ago
Activity icon

Started a new Conversation Call To A Member Function Extension() On Array

I have tried to upload the image using Postman and the image is stored in the preferred directory and the name and is stored in database but i am getting the error response.

public function store(Request $request)
{
    $design_studio = new DesignStudio;
    $design_studio->user_id = 1;
    $design_studio->title = $request->title;
    $design_studio->lang = $request->lang;
    $design_studio->body = $request->body;
    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/slideShow'), $filename);
        $design_studio->image = $request->file('image')->getClientOriginalName();
    }
    if ($sliders = $request->file('sliders')) {
        foreach ($sliders as $slider) {
            $filename = rand(111111, 999999);
            $extension = $request->file('sliders')->extension();
            $getFileExt = $filename + '.' +$extension;
            $slider->move(public_path('images/design-studios/'), $getFileExt);
            $data[] = $getFileExt;
        }
    }
    $design_studio->sliders = json_encode($data);
    $design_studio->save();
    $design_studio->categories()->attach($request->category);
    return redirect()->route('design-studios.index');
}
Jul
24
3 weeks ago
Activity icon

Replied to Uploaded Laravel Project To Cpanel And Get A Blank Page And /public On The Url

change

<IfModule mod_rewrite.c>
	<IfModule mod_negotiation.c>
		Options -MultiViews -Indexes
	</IfModule>

	RewriteEngine On

	# Handle Authorization Header
	RewriteCond %{HTTP:Authorization} .
	RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

	# Redirect Trailing Slashes If Not A Folder...
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_URI} (.+)/$
	RewriteRule ^ %1 [L,R=301]

	# Handle Front Controller...
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^ index.php [L]
</IfModule>
Activity icon

Replied to Strncmp() Expects Parameter 1 To Be String Array Given

How to upload multiple files and save in database.

Activity icon

Replied to Strncmp() Expects Parameter 1 To Be String Array Given

Answer my question.

How to upload multiple files and save in database.