maaz

maaz

Member Since 3 Months Ago

Experience Points
550
Total
Experience

4,450 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 1
550 XP
May
21
1 week ago
Activity icon

Replied to How To Change Boolean Value From 0 To 1 In Laravel On Update.

i solve it by doing this,

 <form method="post" action="{{route('business.approve',$business->id)}}">
                                @csrf
                                <input type="hidden" name="businessID" value="$business->id" />
                                <button class="btn btn-lg btn-success" type="submit">
                                    Approve
                                </button>
                            </form>

Routes:

    Route::post('businessMgt/approve/{id}', '[email protected]')->name('business.approve');

Controller:

  public function postApprove($id)
    {
        $business = Business::where('id', '=', e($id))->first();
        if ($business) {
            $business->is_approved = 1;
            $business->save();
            return redirect()->back();
        }
    }
Activity icon

Replied to How To Change Boolean Value From 0 To 1 In Laravel On Update.

@iljido not working for me. i think i am doing something wrong :(

Activity icon

Replied to How To Change Boolean Value From 0 To 1 In Laravel On Update.

@iljido this seems to be helpful, let me try your method too

Activity icon

Replied to How To Change Boolean Value From 0 To 1 In Laravel On Update.

@yusuf375 how i can do this. let me show you my code

Activity icon

Started a new Conversation How To Change Boolean Value From 0 To 1 In Laravel On Update.

Hello everyone. I have a table like this

table column.

$table->boolean('is_approved')->default(0)->nullable;

what I want to do that when I post something on the front end, in my case it is business it should not appear on the front-end page until admin approved the business, so I created a view on the admin side, where he can see all those not-approved businesses. when the admin click on the Approve button it should change the default of value of 'is_approved' from 0 to 1.

How I can achieve this using a button should I create a form or anything else, give a simple example thankyou 😊

May
20
1 week ago
Activity icon

Started a new Conversation Undefined Variable During Image/file Insertion.

Hi everyone. I got an error during file upload in laravel. I want to just store the filename of an image inside the database on how I can achieve this. error is: " ErrorException Undefined variable: img "

controller:

 public function store(Request $request)
    {
        // dd($request);
        if ($request->hasFile('image')) {
            $img = $request->file('bookcover');
            $extension = $img->getClientOriginalExtension();
            Storage::disk('public')->put($img->getFilename() . '.' . $extension,  File::get($img));
        }


        Business::create([
            'name' => $request->name,
            'asking_price_from' => $request->asking_price_from,
            'asking_price_to' => $request->asking_price_to,
            'description' => $request->description,
            'image' => $img,
            'user_id' => $request->input('user'),
            'category_id' => $request->input('category'),
            'subCategory_id' => $request->input('subCategory'),
            'province_id' => $request->input('province'),
            'city_id' => $request->input('city'),
        ]);
        return redirect('sell-business-form');

form.blade.php

<form action="{{url('/business-store')}}" method="post" class="sell-business-form"
                    enc-type="multipart/form">
                    @csrf
                    <div class="form-group">
                        <label for="name">Name</label>
                        <input type="name" class="form-control" id="name" required />
                    </div>
                    <div class="form-group">
                        <label for="description">Description</label>
                        <textarea name="name" id="description" cols="30" rows="5" class="form-control"
                            required></textarea>
                    </div>
                    <div class="form-group">
                        <label for="a-price">Asking Price</label>
                        <input type="text" class="form-control" names="asking_price_from" id="a-aprice" required />
                    </div>
                    <div class="form-group">
                        <label for="price-t">Asking Price To</label>
                        <input type="text" class="form-control" names="asking_price_to" id="price-t" required />
                    </div>

                    <div class="form-control-inline  my-5 d-flex">
                        {{-- Categories --}}
                        <div class="form-group">
                            <label for="cat">Category</label>
                            <select name="category" id="cat" class="form-control" required>
                                <option value="" selected disabled>select category</option>
                                @foreach ($categories as $category)
                                <option value="{{$category->id}}">{{$category->name}}</option>
                                @endforeach
                            </select>
                        </div>
                        {{-- sub categories --}}
                        <div class="form-group ml-5">
                            <label for="subcat">Sub Category</label>
                            <select name="subCategory" id="subcat" class="form-control" required>
                                <option value="" selected="false">select sub category</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-control-inline  my-5 d-flex ">
                        {{-- province --}}
                        <div class="form-group ">
                            <label for="province">Select Province</label>
                            <select id="province" name="province" class="form-control">
                                <option value="" selected disabled>Select Province</option>
                                @foreach ($provinces as $province)
                                <option value="{{$province->id}}">{{$province->name}}</option>
                                @endforeach
                            </select>
                        </div>

                        {{-- cities --}}
                        <div class="form-group ml-5 ">
                            <label for="city">Select Cities</label>
                            <select id="city" name="city" class="form-control">
                                <option value="" selected="false">City</option>
                            </select>
                        </div>
                    </div>

                    {{-- file/image --}}
                    <div class="form-group">
                        <input type="file" class="form-control border" name="image" required />
                    </div>
                    <input type="hidden" name="user" value="{{ Auth()->user()->id }}">
                    <button type="submit" class="button-primary float-right">
                        Post Business
                    </button>
                </form>

is there any other way to achieve this.. i am doing this for testing purpose.

the error is in the image field..

May
17
2 weeks ago
Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

@michaloravec if it works don't touch it haha. by the way thanks a lot @michaloravec :)

Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

@michaloravec i just done it by adding this to my code.

  public function getStates($id)
    {

        $states = State::where('country_id', $id)->pluck('name', 'id');
        return response()->json($states);
    }
}

return resonse()->json($state) it works

Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

@michaloravec

 public function getStates($id)
    {

        $states = State::where('country_id', $id)->pluck('name', 'id');
        dd($states);
    }

i am getting data when i visit the /getStates/1

Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

@michaloravec thanks for you precious time buddy, it will be great if you solve my this problem :)

Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

@michaloravec yes I have data in my countries and states table. I also make their relationship so there should be no problem.

Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

@michaloravec now there is no error in the console. but I didn't get my required results.

Activity icon

Replied to Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

(index):47 Uncaught ReferenceError: JQuery is not defined
    at HTMLSelectElement.<anonymous> ((index):47)
    at HTMLSelectElement.dispatch (app.js:11800)
    at HTMLSelectElement.elemData.handle (app.js:11604)

but jquery is loaded already

Activity icon

Started a new Conversation Dynamic Dependent Drop Down Box Not Working Using Ajax In Laravel .

i was looking for a dynamic dependent dropdown selectbox, so i found a video i copy the code line by line from him but my code is not working idk why. here is my MainController.php

<?php

namespace App\Http\Controllers;

use App\State;
use App\Country;
use Illuminate\Http\Request;

class MainController extends Controller
{
    public function index()
    {
        $countries = Country::all();
        return view('index', compact('countries'));
    }

    public function getStates($id)
    {
        $states = State::where('country_id', $id)->pluck('name', 'id');
        return json_encode($states);
    }
}

My routes:

Route::get('/', '[email protected]')->name('index');
Route::get('/getStates/{id}', '[email protected]')->name('getStates');

index.blade.php:

  <div class="panel panel-primary">
        <div class="panel-heading">
            <h2 class="text-center">Multi Dropdown</h2>
        </div>
        <div class="panel-body">
            <div class="col-md-3">
                <select name="country" id="country" class="form-control">
                    <option value="" selected="false">Country</option>
                    @foreach ($countries as $country)
                    <option value="{{$country->id}}">{{$country->name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-md-6 mt-3">
                <select name="state" id="state" class="form-control">
                    <option value="" selected="false">State</option>
                </select>
            </div>
        </div>

        <div class="col-md-3 mt-3">
            <button class="btn btn-primary rounded" type="submit" name="search">Search <i
                    class="fa fa-search"></i></button>
        </div>
    </div>

Jquery code:

<script type="text/javascript">
    jQuery(document).ready(function (){
        jQuery('select[name="country"]').on('change',function(){
            var countryID = jQuery(this).val();
            if (countryID) {
                JQuery.ajax({
                    url:'/getStates/'+countryID,
                    type: 'GET',
                    dataType:'json',
                    success:function(data){
                        jQuery('select[name="state"]').empty();
                        jQuery.each(data,function(key,value){
                            $('select[name="state"]').append('<option value="'+ key +'">'+value+'</option>');
                        });
                    }
                });
            }
            else{
                $('select[name="state"]').empty();
            }
        });
    });
</script>

it is not working :(

May
16
2 weeks ago
Activity icon

Replied to Approve Post On Admin Dashboard

Thanks, @sergiu17 let me try :)

Activity icon

Started a new Conversation Approve Post On Admin Dashboard

Hello everyone. I am working on a project where Seller can post a business for sale. So I created a Business Schema like this.

 public function up()
    {
        Schema::create('businesses', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('category_id');
            $table->unsignedBigInteger('subCategory_id');
            $table->unsignedBigInteger('province_id');
            $table->unsignedBigInteger('city_id');

            $table->string('name');
            $table->float('asking_price_from');
            $table->float('asking_price_to');
            $table->string('description');
            $table->boolean('featured')->nullable();
            $table->string('image');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
            $table->foreign('subCategory_id')->references('id')->on('sub_categories')->onDelete('cascade');
            $table->foreign('province_id')->references('id')->on('provinces')->onDelete('cascade');
            $table->foreign('city_id')->references('id')->on('cities')->onDelete('cascade');
        });
    }

Now I want, that when the user/seller posts the business on the front-end. Admin will approve the business/post after admin approval it will be showing on the main page or home page etc. Now, what changes I need to do in the Business schema. Plz tell me what should i do next.

May
14
2 weeks ago
Activity icon

Replied to Trying To Get Property 'name' Of Non-object

@michaloravec thanks man it works for me :) it was my bad i didn't follow laravel convention.

Activity icon

Replied to Trying To Get Property 'name' Of Non-object

basically I want to insert subcategory into the main category. I want to select the main category which will be coming from the category table and insert the subcategory into that category.

Activity icon

Replied to Trying To Get Property 'name' Of Non-object

@snapey should i change it to category_id ?

Activity icon

Replied to Trying To Get Property 'name' Of Non-object

yes, @michaloravec every subcategory has a category.

Activity icon

Replied to Trying To Get Property 'name' Of Non-object

@forelse ($subCategories as $subCategory) {{ $subCategory->id}}
                    {{ $subCategory->category->name }}

                    {{$subCategory->name}}
                    @empty

                    @endforelse

                </tbody>

also gives the same error :(

Activity icon

Replied to Trying To Get Property 'name' Of Non-object

i try both these solutions but it dosent work.

Activity icon

Replied to Trying To Get Property 'name' Of Non-object

it dosent work for me :(

Activity icon

Started a new Conversation Trying To Get Property 'name' Of Non-object

I have two model Category and SubCategory. I want to show the category name in the subcategory view. How can I achieve this? The same code works fine in my other project.

view code:

  @forelse ($subCategories as $subCategory)
                        <tr>
                            <td>{{$subCategory->id}}</td>
                            <td>{{$subCategory->category->name}}</td>
                            <td>{{$subCategory->name}}</td>
                        </tr>
                        @empty

                        @endforelse

SubCategory Controller:

    public function index()
    {
        $subCategories = SubCategory::all();
        $categories = Category::all();

        return view('admin.subCategory-mgt.all-subCat', compact('subCategories', 'categories'));
    }

Category Model:

public function subCategories()
    {
        return $this->hasMany('App\SubCategory');
    }

SubCategory Model;

public function category()
    {
        return $this->belongsTo('App\Category');
    }