mada72

mada72

Member Since 5 Months Ago

Experience Points 2,860
Experience Level 1

2,140 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 14
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

07 Aug
1 month ago

mada72 left a reply on Create New Item

@ajithlal

Thank you very much for help!

@snapey

You are a good teacher ...Thank you very much !

mada72 left a reply on Create New Item

somebody with a solution?

06 Aug
1 month ago

mada72 left a reply on Create New Item


Too few arguments to function App\Http\Controllers\AdminBarcodesController::store(), 1 passed and exactly 2 expected

mada72 left a reply on Create New Item

mmmm...I still have the same error

mada72 left a reply on Create New Item

what is wrong?

mada72 left a reply on Create New Item

yes...I can be more precise

I changed it like this

<tbody>
        @if ($books)
            @foreach($books as $book)
                <tr>
                    <td>{{$book->id}}</td>
                    <td>
                        <img height="50" src="{{$book->photo ? asset($book->photo->file) :'http://place-hold.it/400x400'}}" alt="">
                    </td>
                    <td><a href="{{route('books.edit', $book->id)}}">{{$book->title}}</a></td>
                    <td>{{$book->author ? $book->author->name : 'uncateg'}}</td>
                    <td>{{$book->edition}}</td>
                    <td>{{$book->year}}</td>
                    <td>{{$book->isbn}}</td>
                    <td>{{$book->description}}</td>
                    <td>{{$book->barcode->count()}}</td>
                    <td>{{$book->rentCount->count()}}</td>
                    <td>
                        @if(abs($book->barcode->count() - $book->rentCount->count())> 0)
                            @if($book->rents)
                                <a href="{{route('rents.create')}}">Rent</a>
                            @else
                                <a href="{{route('rents.edit')}}">Return</a>
                            @endif
                         @else
                            Rented
                        @endif
                    </td>
                    <td>{{$book->created_at}}</td>
                    <td>{{$book->updated_at}}</td>
                    <td>
                        {!! Form::open(['method'=>'POST', 'action'=>'[email protected]','files'=>true]) !!}

                        <div class="form-group">
                            {!! Form::submit('Create BookItem', ['class'=>'btn btn-primary']) !!}
                        </div>
                        {!! Form::close() !!}
                    </td>
                </tr>

            @endforeach
        @endif
        </tbody>

Barcodes Controller

public function store(Request $request,$id )
    {
        $book = Book::findOrFail($id);
        $barcode = Barcode::create(['book_id' => $book->id]);
        $barcode->save();
        $test =Barcode::findOrFail($barcode->id);
        //dd($test);
        $book_item= $book->isbn . $barcode->id;
        $test->update(['book_item' => $book_item]);
        return redirect('/admin/barcodes');
    }

error

Too few arguments to function App\Http\Controllers\AdminBarcodesController::store(), 1 passed and exactly 2 expected

to understand: 1.you have a book

  1. a book can have more copies(BookItem)

I want : onClick button "Ctreate BookItems" to create another copy for this book like BookItem

Barcode(BookItem)

class Barcode extends Model
{
    protected $fillable = ['book_id', 'book_item'];

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

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

    public function countAvailableBooks()
    {
        return $this->hasMany(Rent::class)->whereHas('return_date')->count();
    }
}

@ajithlal

Thank you for help!

mada72 left a reply on Create New Item

don't work...I need the book->id

mada72 left a reply on Create New Item

Create BookItem can be also a button...

mada72 left a reply on Create New Item

sorry...I don't understand :(

mada72 left a reply on Create New Item

view Create Items

<h1>Create BookItem</h1>
    {!! Form::open(['method'=>'POST', 'action'=>'[email protected]','files'=>true]) !!}
    <div class="form-group">
        {!! Form::label('book_title', 'Title:') !!}
        {!! Form::text('book_title', null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('book_isbn', 'Isbn:') !!}
        {!! Form::text('book_isbn', null, ['class'=>'form-control']) !!}
    </div>

    <div class="form-group">
        {!! Form::submit('Create BookItem', ['class'=>'btn btn-primary']) !!}
    </div>
    {!! Form::close() !!}

but I think this is not good...

mada72 started a new conversation Create New Item

Hello,

I have a book and I need to create more copies(Create BookItems) I don't know how can get the id for book to create an item for this book

books.index

<tbody>
        @if ($books)
            @foreach($books as $book)
                <tr>
                    <td>{{$book->id}}</td>
                    <td>
                        <img height="50" src="{{$book->photo ? asset($book->photo->file) :'http://place-hold.it/400x400'}}" alt="">
                    </td>
                    <td><a href="{{route('books.edit', $book->id)}}">{{$book->title}}</a></td>
                    <td>{{$book->author ? $book->author->name : 'uncateg'}}</td>
                    <td>{{$book->edition}}</td>
                    <td>{{$book->year}}</td>
                    <td>{{$book->isbn}}</td>
                    <td>{{$book->description}}</td>
                    <td>{{$book->barcode->count()}}</td>
                    <td>{{$book->rentCount->count()}}</td>
                    <td>
                        @if(abs($book->barcode->count() - $book->rentCount->count())> 0)
                            @if($book->rents)
                                <a href="{{route('rents.create')}}">Rent</a>
                            @else
                                <a href="{{route('rents.edit')}}">Return</a>
                            @endif
                         @else
                            Rented
                        @endif
                    </td>
                    <td>{{$book->created_at}}</td>
                    <td>{{$book->updated_at}}</td>
                    <td><a href="{{route('barcodes.create')}}">Create BookItem</a></td>
                </tr>
            @endforeach
        @endif
        </tbody>

BookItem Controller

public function create(){
?????
}

public function store(Request $request )
    {
      $book = ????
        $barcode = Barcode::create(['book_id' => $book->id]);
        $barcode->save();
        $test =Barcode::findOrFail($barcode->id);
        //dd($test);
        $book_item= $book->isbn . $barcode->id;
        $test->update(['book_item' => $book_item]);
        return redirect('/admin/barcodes');
    }

Thx!

04 Aug
1 month ago

mada72 left a reply on Update Quantity

Thank you!!!

02 Aug
1 month ago

mada72 left a reply on Update Quantity

I can't find the correct way :(

mada72 left a reply on Update Quantity

add_quantity

@tykus

Thank you for help :)

mada72 left a reply on Update Quantity

I am updating the quantity to whatever the user inputs in a form

@tykus

mada72 left a reply on Update Quantity

@tykus

I can't change quantity(my teacher's rules)...I need to open a new form and make update just for quantity(I need to add quantity)...maybe I can make another fuction :public function update_qty?

mada72 left a reply on Update Quantity

@munazzil

don't work...

mada72 started a new conversation Update Quantity

Hello,

I try to update quantity for one product but I have update for all products..

ProductsController

 public function update(Request $request, $id)
    {
        $product=Product::findOrFail($id);
        $product->update(['quantity'=>$request->get('quantity')]);

        $new_quantity = $request->all()['add_quantity'] ;
        DB::table('products')->increment('quantity', $new_quantity);

        $input = $request->all();
        if($file = $request->file('photo_id')){
            $name = time() . $file->getClientOriginalName();
            $file->move('images', $name);
            $photo = Photo::create(['file'=>$name]);
            $input['photo_id'] = $photo->id; //
        }
        $product->update($input);

        return redirect('/admin/products');
    }

edit.blade.php

<div class="col-md-6">
    {!! Form::model($product,['method'=>'PATCH', 'action'=>['[email protected]', $product->id],
    'files'=>true])
     !!}
    <div class="form-group">
        {!! Form::label('photo_id', 'Photo:') !!}
        {!! Form::file('photo_id', null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('name', 'Name:') !!}
        {!! Form::text('name', null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('title', 'Title:') !!}
        {!! Form::text('title', null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('description', 'Description:') !!}
        {!! Form::textarea('description',null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('price', 'Price:') !!}
        {!! Form::text('price' ,null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('quantity', 'Quantity:') !!}
        {!! Form::text('quantity' ,null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('category_id', 'Category:') !!}
        {!! Form::select('category_id', [''=>'Choose options'] + $categories, null, ['class'=>'form-control']) !!}
    </div>
    </div>
        <div class="col-md-6">
            <div class="form-group">
                {!! Form::label('add_quantity', 'Add Quantity:') !!}
                {!! Form::text('add_quantity' ,null, ['class'=>'form-control']) !!}
            </div>

        </div>
    <div class="form-group">
        {!! Form::submit('Update Product', ['class'=>'btn btn-primary']) !!}
    </div>
    {!! Form::close() !!}
    {!! Form::open(['method'=>'DELETE', 'action'=>['[email protected]', $product->id],
       'files'=>true])
        !!}
    <div class="form-group">
        {!! Form::submit('Delete Product', ['class'=>'btn btn-danger']) !!}
    </div>
    {!! Form::close() !!}

what is wrong?

01 Aug
1 month ago

mada72 left a reply on View Message

@tykus

Thank you!

I try now to learn Laravel...sometimes I do "stupid" things like

$product->update(['quantity' => $product->quantity - $item->qty]);

You have right :)

mada72 left a reply on View Message

I tried but don't work... I don't know how to do that correct...:(

mada72 started a new conversation View Message

Hello,

I try to send a message to view page when products->quantity < item->quantity(shopping_cart). If this conidition is true for one product, I have the same message for all products. So, something is wrong...but I don't know what... :(

frontcontroller:

 $message = [];
        foreach (Cart::content() as $item) {
            $product = Product::find($item->id);
            if ($product->quantity - $item->qty < 0) {
                $message = 'Not enough products';
                $product->update(['quantity' => $product->quantity - $item->qty]);

               
            }else{
                $mes = 'ok';
            }
        }

        return view('cart',compact('token','cart', 'message', 'mes')
        );

view page

 @foreach($cart as $item)

                                    <tr>
                                        
                                        <td class="cart_description">
                                            <h4><a href="">{{ $item->name }}</a></h4>
                                            <p>Code:{{ $item->id }}</p>
                                        </td>
                                        <td class="cart_price">
                                            <p>€{{ $item->price }}</p>
                                        </td>

                                        <td class="cart_quantity">
                                            <div class="cart_quantity_button">
                                                <a class="cart_quantity_up" href="{{url("cart?product_id=$item->id&increment=1")}}"> + </a>
                                                <input class="cart_quantity_input text-center" type="text" name="quantity" value="{{ $item->qty }}" autocomplete="off" size="2">
                                                <a class="cart_quantity_down" href="{{url("cart?product_id=$item->id&decrease=1")}}"> - </a>
                                            </div>
                                        </td>
                                        <td class="cart_total">
                                            <p class="cart_total_price">€{{ $item->subtotal }}</p>
                                        </td>
                                        @if($message)
                                            <td class="cart_price">
                                            <p > {{ $message }}  </p>
                                        </td>
                                        @endif
                                        <td class="cart_delete">
                                            <a type="button" class="btn btn-danger btn-sm cart_quantity_delete " href="{{url("cart?product_id=$item->id&delete=1")}}"><i class="fa fa-times"></i>Remove</a>
                                        </td>
                                    </tr>
                                @endforeach
                                @else
                                    <p class="alert-info">No items in shopping cart</p>

                                @endif

I want to have for every product message : "ok" of "'Not enough products in stock"

Thank you!

15 Jul
2 months ago

mada72 left a reply on User- Delivery Address - Many To Many

@cronix


 public function deliveries(){
        return $this->belongsToMany('App\Delivery')->latest();
    }

nothing changed..in my DB the timestamp is the same(update_at) I don't know if in controller "firstOrCreate" is correct..

mada72 left a reply on User- Delivery Address - Many To Many

@mstrauss In my opinion..yes EX: wife and husband have the same delivery address( no the same order) In fact I was thinking for a option like: check your order before to pay. If all is correct go to payment

mada72 started a new conversation User- Delivery Address - Many To Many

Hello,

I have user-delivery address a relation many-to-many I want to get delivery address in my order but I don't know what the last address is(no last in my DB) In controller I used "firstOrcreate"

User

public function deliveries(){
        return $this->belongsToMany('App\Delivery');
    }

Delivery

public function users()
    {
        return $this->belongsToMany('App\User');
    }

Controller

public function step2(Step2Request $request)
    {

        $city = City::firstOrCreate([
            'postal_code' => $request['postal_code'],
            'name' => $request['name'],
            'country_id' => $request['country'],
        ]);

        $delivery = Delivery::firstOrCreate([
            'street' => $request['street'],
            'house_nr' => $request['house_nr'],
            'bus' => $request['bus'],
            'city_id' => $city->id,
        ]);
        $user = Auth::user();
        $user->deliveries()->syncWithoutDetaching($delivery->id);

        session(['delivery_id' => $delivery->id]);

        $myCountry = Country::findOrFail($request['country']);
        session(['shipment' => $myCountry->shipment]);
        $ship_cost = session('shipment');
        $address = Address::where('id', '=', Auth::user()->address_id)->first();


        return view('order', compact('ship_cost','address'));

    }

How can I know the last delivery(the most recent) address?

mada72 left a reply on Get Address In Order

Oooo...yes

Thank you! @Cronix

mada72 started a new conversation Get Address In Order

Hello,

I try to get de user address in my order

Controller

$address = Address::where('id', '=', Auth::user()->address_id)->get();
        //dd($address);

        return view('order', compact('ship_cost','address'));

View blade

<main>
        <div class="col-md-6 mx-md-3">
            <p>Name:@auth {{Auth::user()->first_name}} {{Auth::user()->last_name}} @endauth</p>
            <p>Address: {{$address->street}}, {{$address->house_nr}}</p>

        </div>

I have an error..

10 Jul
2 months ago

mada72 left a reply on Get Everything From Table With Every Related Data From Many To Many Relations

User::with('knownLanguage')->get()->pluck('hidden_id', 'nick_name', 'first_name', 'last_name', 'date_of_birth', 'about_me', 'profile_photo', 'country', 'gender');

09 Jul
2 months ago

mada72 left a reply on Product And Cart Price

I have to learn a lot ... Thank you! @Snapey

mada72 started a new conversation Product And Cart Price

Hello,

I have product-price-decimal number (10.00) only in my shopping cart is integer(10)

product

Schema::create('products',function(Blueprint $table) {
            $table->increments('id');
            $table->integer('photo_id')->nullable();
            $table->integer('category_id');
            $table->string('name', 191)->unique();
            $table->string('title', 140);
            $table->string('description', 500);
            $table->decimal('price',8,2);
            $table->integer('quantity')->unsigned();
            $table->timestamps();

controller

public function cart(){
        if(Request::isMethod('post')){
            $product_id = Request::get('product_id');
            $product = Product::find($product_id);
            //dd($product);
            Cart::add(array('id' => $product_id, 'name' => $product->name, 'qty' => 1, 'price' => $product->price));
        }
        $cart = Cart::content();

why?

08 Jul
2 months ago

mada72 left a reply on Confirm Address And After Pay

Which is the easiest way for:

  1. save delivery address in db
  2. if 1 . is true go to payment(pay now)

mada72 left a reply on Confirm Address And After Pay

if click "confirm address" I have error: Undefined variable: cart (....\resources\views\checkout.blade.php)

If click "pay now" my address is not save in db

mada72 left a reply on Confirm Address And After Pay

I am open for another solution....I want to save delivery address in db and after pay It is my first website

mada72 started a new conversation Confirm Address And After Pay

Hello,

I need a condition/connection between "confirm address" and "pay now" Confirm address = save delivery address in my db Pay now = link with stripe

I need something like: if address is not confirmated you can't pay

Front controller:

public function step2(Step2Request $request){

        $city = City::firstOrCreate([
            'postal_code' => $request['postal_code'],
            'name' => $request['name'],
            'country_id' => $request['country'],
        ]);

        $delivery = Delivery::firstOrCreate([
            'street' => $request['street'],
            'house_nr' => $request['house_nr'],
            'bus' => $request['bus'],
            'city_id' => $city->id,
        ]);
        $user = Auth::user();
        $user->deliveries()->syncWithoutDetaching($delivery->id);

        session(['delivery_id' => $delivery->id]);

        $myCountry = Country::findOrFail($request['country']);
        session(['shipment' => $myCountry->shipment]);
        $ship_cost = session('shipment');
        return view('checkout', compact('ship_cost'));
    }

    public function checkout(){


        if(Request::isMethod('post')){
            $product_id = Request::get('product_id');
            $product = Product::find($product_id);
            Cart::add(array('id' => $product_id, 'name' => $product->name, 'qty' => 1, 'price' => $product->price));
        }
        $cart = Cart::content();
        //increment
        if (Request::get('product_id') && (Request::get('increment')) == 1) {
            $item = Cart::search(
                function($key, $value) {
                    return $key->id == Request::get('product_id');
                })->first();
            Cart::update($item->rowId, $item->qty + 1);
        }
        if (Request::get('product_id') && (Request::get('decrease')) == 1) {
            $item = Cart::search(function($key, $value) { return $key->id == Request::get('product_id'); })->first();
            Cart::update($item->rowId, $item->qty - 1);

        }

        $myCountry = Country::where('id', 1)->first();
        $ship_cost = '1.00';
        return view('checkout', compact ('cart', 'token','cities', 'cit','countries', 'addresses','myCountry', 'ship_cost'));
    }


web

Route::post('step2', '[email protected]')->name('step2');
Route::get('/checkout', '[email protected]')->name('checkout');

checkout.blade

 @if(!Auth::check())
                <a href ="{{route('login')}}"  class="btn btn-danger">
                    <i class="fas fa-shopping-basket"></i>First login</a>
            @else
                <div class="col-md-5">
                        <div class="d-md-flex">
                            <div class="mr-3" >
                                <label for="first_name">First name</label>
                                <input type="text" class="form-control mb-2 mr-md-3 " name="first_name" placeholder="Firstname" @auth value="{{Auth::user()->first_name}}" @endauth>
                            </div>
                            <div >
                                <label for="last_name">Last name</label>
                                <input type="text" class="form-control mb-2 mr-md-5" name="last_name" placeholder="Lastname" @auth value="{{Auth::user()->last_name}}" @endauth>
                            </div>
                        </div>
                    <h5>Delivery Address</h5>
                    <form action="{{route('step2')}}" method="POST">
                        @csrf
                        @method('POST')

                        <input type="text" class="form-control mb-2" name="street" placeholder="Addresss" required>
                        <div class="d-flex">
                            <input type="text" class="form-control mb-2 mr-3" name="house_nr" placeholder="Number" required>
                            <input type="text" class="form-control mb-2 ml-3" name="bus" placeholder="Bus">
                        </div>
                        <input type="text" class="form-control mb-2" name="postal_code" placeholder="Postal code" required>
                        <input type="text" class="form-control mb-2" name="name" placeholder="City" required>
                        <div class="form-group d-flex">
                            <label for="country2" class="pr-3 pt-1">Country</label>
                            <select class="form-control" id="country2" name="country">
                                @php($countries = \App\Country::all())
                                @foreach($countries as $country)
                                    <option value="{{$country->id}}" @auth @if(Auth::user()->address->city->country->id == $country->id) selected @endif @endauth>{{$country->name}}</option>
                                @endforeach
                            </select>
                        </div>
                        <button class="btn btn-dark text-uppercase" type="submit">Confirm address</button>

                    </form>
                    <div class="my-2">
                        <a href ="{{url('stripe')}}"  class="btn btn-success">
                            <i class="fas fa-shopping-basket"></i> Pay now
                        </a>
                    </div>

                </div>
                <div col-md-7>
                    @if(count($cart))
                            <h4 class="d-flex justify-content-between align-items-center mb-3">
                                <span class="text-muted">Your cart</span>
                                <span class="badge badge-secondary badge-pill">{{count($cart)}}</span>
                            </h4>
                        @foreach($cart as $item)
                                <ul class="list-group  mb-3">
                                    <li class="list-group-item d-flex justify-content-between lh-condensed">
                                        <div>
                                            <h6 class="my-0">{{ $item->name }}</h6>
                                        </div>
                                        <div >
                                            <span class="text-muted mx-5">{{ $item->qty }}</span>
                                            <span class="text-muted">€{{ $item->price }}</span>
                                        </div>
                                    </li>
                                    @endforeach
                                    <li class="list-group-item d-flex justify-content-between bg-light">
                                        <div class="text-primary">
                                            <h6 class="my-0">Shipping</h6>
                                        </div>
                                        <span class="text-primary">€ {{$ship_cost}}</span>
                                    </li>
                                    <li class="list-group-item d-flex justify-content-between bg-light">
                                        <div class="text-success">
                                            <h6 class="my-0">Promo code</h6>
                                            <small>EXAMPLECODE</small>
                                        </div>
                                        <span class="text-success">-</span>
                                    </li>
                                    <li class="list-group-item d-flex justify-content-between">
                                        <span>Total (EUR)</span>
                                        <strong>€ {{Cart::subTotal() + $ship_cost}}</strong>
                                    </li>
                                </ul>
                                <form class="card p-2">
                                    <div class="input-group">
                                        <input type="text" class="form-control" placeholder="Promo code">
                                        <div class="input-group-append">
                                            <button type="submit" class="btn btn-secondary">Redeem</button>
                                        </div>
                                    </div>
                                </form>
                </div>
                @else
                    <p class="alert-info">No items in shopping cart</p>
        </div>

           @endif
    @endif

04 Jul
2 months ago

mada72 left a reply on Auth With IsAdmin

my mistake

correct in web

Auth::routes();
Route::get('/admin','[email protected]')->middleware('admin');

now it is ok :)

Thank you very much! @Nakov

mada72 left a reply on Auth With IsAdmin

and my route

web

Auth::routes();
Route::get('/admin','[email protected]');
Route::get('my-orders', '[email protected]')->name('orders.index');
Route::get('my-orders/{order}', '[email protected]')->name('orders.show');

Route::group(['middleware'=>'admin'],function(){
    Route::prefix('admin')->group(function () {

        Route::resource('users', "AdminUsersController");
        Route::resource('users', "AdminUsersController");
        Route::resource('addresses', "AdminAddressesController");
        Route::resource('countries', "AdminCountriesController");
        Route::resource('cities', "AdminCitiesController");
        Route::resource('categories', "AdminCategoriesController");
        Route::resource('products', "AdminProductsController");

mada72 left a reply on Auth With IsAdmin

This is my first website

Kernel

 protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'admin' => \App\Http\Middleware\Admin::class,
    ];

mada72 started a new conversation Auth With IsAdmin

Hello, I have a problem with function isAdmin of I don't know to use correct . After login from my home page I can go in my dashboard page with every user and that is not correct.

User


class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'first_name', 'last_name', 'email', 'password', 'role_id' , 'address_id','is_active'
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
    public function role()
    {
        return $this->belongsTo('App\Role');
    }
    
    public function isAdmin()
    {
        if ($this->role->name == 'Admin' && $this->is_active == 1) {
            return true;
        }
        return false;
    }

Role

class Role extends Model
{
    //
    protected $fillable = ['name'];


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

}

Admin

class Admin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::check() && Auth::user()->isAdmin()){
            return $next($request);
        }
        return redirect('/');
    }
}

RedirectIfAuth


namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/');
        }

        return $next($request);
    }
}

thx!

29 Jun
2 months ago

mada72 left a reply on Seed Photo

Thank you!!! @Jaytee

27 Jun
2 months ago

mada72 left a reply on Seed Photo

@jaytee

I will try...thx! :)

@redhatranger

sure...but wat is your error?

mada72 left a reply on Seed Photo

Sorry....that is wrong...I was trying something and I forgot to delete I think that I mixed 3 different things: my seed with my Controller and my index Is necessary to seed a photo? In fact I don't understand this circuit

mada72 left a reply on Seed Photo

I don't know how...I tried in inspect element and then work that path is ok if I upload photos from my computer

mada72 started a new conversation Seed Photo

Hello,

I made: php artisan db:seed- but I can't see my photos

Photo factory

use App\Photo;
use Faker\Generator as Faker;

$factory->define(Photo::class, function (Faker $faker) {
    return [
        'file'=>$faker->imageUrl($width = 400, $height = 400) ,
    ];
});

ProductContrller

public function store(Request $request)
    {
        //dd($request->all());
        $input = $request->all();//alle velden uit het formulier in $input
        if($file = $request->file('photo_id')){
            $name = time().$file->getClientOriginalName();//samenstelling bestandsnaam
            $file->move('images', $name);//het kopieren naar de map images
            $photo = Photo::create(['file'=>$name]);//in de tabel photo id en naam aanmaken
            $input['photo_id'] = $photo->id; //
        }

        $product = new Product();

product index blade

extends('layouts.admin')
@section('content')
    <h1>All Products</h1>
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">Photo</th>
            <th scope="col">Name</th>
            <th scope="col">Category</th>
            <th scope="col">Title</th>
            <th scope="col">Description</th>
            <th scope="col">Price</th>
            <th scope="col">Quantity</th>
            <th scope="col">Created</th>
            <th scope="col">Updated</th>
        </tr>
        </thead>
        <tbody>
        @if ($products)
            @foreach($products  as $product)
                <tr>

                    <td>
                        <img height="50" src="{{$product->photo ? asset($product->photo->file) : '' . ' https://via.placeholder.com/100x100'}}" alt="">
                    </td>

inspect element for photo

<img height="50" src="http://localhost/larabijoux/public/images/https://lorempixel.com/640/480/?46563" alt="">

that is not correct....but I don't know how is correct

Thx!

mada72 left a reply on Update Stock

thank you very much!!! @c

23 Jun
2 months ago

mada72 left a reply on Update Stock

In my view page I must "say" to user: " We don't have enough items in stock' And that must be : do something

mada72 left a reply on Update Stock

I miss that "do you logic here" my neurons don't work :)

mada72 left a reply on Update Stock

ignore 'Add to cart successful'

mada72 left a reply on Update Stock

I tried something like this...

if($product->quantity >= $item->qty)
             $product->update(['quantity' => $product->quantity - $item->qty]);

        }return redirect()->route('shopping_cart')
        ->with('message', 'Add to cart successful');