mada72

mada72

Member Since 3 Months Ago

Experience Points 1,330
Experience Level 1

3,670 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 2
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.

15 Jul
4 days 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
1 week 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
1 week 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
1 week 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', 'FrontController[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 weeks 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 weeks ago

mada72 left a reply on Seed Photo

Thank you!!! @Jaytee

27 Jun
3 weeks 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
3 weeks 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');

mada72 left a reply on Update Stock

my function work but if I have $product->quantity =5 and $item->qty=7 my stock will be negative -2

I need to return a error in view

mada72 left a reply on Update Stock


protected $table = 'products';
    protected $fillable=['photo_id','category_id','name','title','description','price','quantity'];

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

    /*public function stock(){
        return $this->hasMany('App\Stock');
    }*/
    public function order(){
        return $this->belongsToMany('App\Order', 'order_product', 'product_id', 'order_id');
    }

mada72 started a new conversation Update Stock

Hello,

if( $product->quantity - $item->qty < 0)....return..???

I need a condition...can you help me please?

my code

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);

        }

        $this->decreaseQuantities();


        return view('checkout', compact ('cart', 'token','cities', 'cit','countries', 'addresses'));
    }

    public function decreaseQuantities()
    {
        foreach (Cart::content() as $item) {
            $product = Product::find($item->id);
            $product->update(['quantity' => $product->quantity - $item->qty]);

        }
    }

Thx!

15 Jun
1 month ago

mada72 left a reply on Stripe Payment

@Snapey

Package operations: 1 install, 0 updates, 1 removal
  - Removing bumbummen99/shoppingcart (2.8.1)
  - Installing stripe/stripe-php (v6.37.1): Downloading (100%)

mada72 left a reply on Stripe Payment

I use this for add to cart

mada72 started a new conversation Stripe Payment

Hello,

I installed Stripe for payment and I seen that Stripe removed bumbummen99/shoppingcart

Why? It is correct?

11 Jun
1 month ago

mada72 left a reply on Product-order

please...I need help

mada72 started a new conversation Product-order

I try to build orders-products but I don't know if that is correct

namespace App;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $fillable = ['user_id', 'quantity','order_nr', 'issue_date', 'status'];

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

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

product


use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $primaryKey = 'id';
    protected $table = 'products';
    protected $fillable=['photo_id','name','title','description','price'];

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

    public function stock(){
        return $this->hasMany('App\Stock');
    }
    public function order(){
        return $this->belongsToMany('App\Order');
    }

user

public function role()
    {
        return $this->belongsTo('App\Role');
    }
    public function photo(){
        return $this->belongsTo('App\Photo');
    }
    public function address()
    {
        return $this->belongsTo('App\Address');
    }
    public function order()
    {
        return $this->hasMany('App\Order');
    }


    ```
stock

`class Stock extends Model
{
    protected $fillable = ['product_id','quantity'];


    public function product()
    {
        return $this->belongsTo('App\Product');
    }
13 May
2 months ago

mada72 left a reply on Concatenating And Saving To DB

@Cronix

If I want something like this...work?


User :: where(['barcode' => request('user_barcode')])->first();

06 May
2 months ago

mada72 left a reply on Create BookItem

@Snapey

If I did something wrong tell me ...I must understand...please

mada72 left a reply on Create BookItem

@Snapey

I have this in Book.php A book can have many barcodes(every copy have a barcode) I try to understand Laravel...

mada72 left a reply on Create BookItem

yes...in barcodes/index.blade.php


 <h1>All Barcodes</h1>
    <p>Total BookItem: {{$bookItem}}</p>
    <div class="col-md-6">
        <table class="table table-striped">
            <thead>
            <tr>
                <th scope="col">Id</th>
                <th scope="col">Isbn</th>
                <th scope="col">Book</th>
                <th scope="col">Barcode</th>
                <th scope="col">Status</th>
                <th scope="col">Created</th>
                <th scope="col">Updated</th>
            </tr>
            </thead>
            <tbody>
            @if ($barcodes)

                @foreach($barcodes as $barcod)
                    <tr>
                        <td>{{$barcod->id}}</td>
                        <td><a href="{{route('barcodes.edit', $barcod->id)}}">{{$barcod->book->isbn}}</a></td>
                        <td>{{$barcod->book ? $barcod->book->title : 'Uncategorized'}}</td>
                        <td>{!!  DNS1D::getBarcodeHTML($barcod->book->isbn . $barcod->id, "C128" ,1,20)!!}
                            <div style="padding-top: 0px; padding-left: 20px;  width: 300px;">{{$barcod->book->isbn}} {{$barcod->id}}<br></div>
                            {{--<style>
                                .code{
                                    height: 60px !important;
                                }

                            </style>--}}
                        </td>
                        <td>{{$barcod->created_at ? $barcod->created_at->diffForHumans() : 'no date'}}</td>
                        <td>{{$barcod->updated_at ? $barcod->updated_at->diffForHumans() : 'no date'}}</td>

                    </tr>
                @endforeach
            @endif
            </tbody>
        </table>
    </div>
    <div class="col-md-6">

    </div>

I have to know what copy was borrowed

mada72 left a reply on Create BookItem

and my barcodes/create.blade.php


<h1>Create Barcode</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::label('status', 'Status:') !!}
        {!! Form::text('status' ,null, ['class'=>'form-control']) !!}
    </div>
    <div class="form-group">
        {!! Form::submit('Create Barcode', ['class'=>'btn btn-primary']) !!}
    </div>
    {!! Form::close() !!}
    @include('includes.form_error')

mada72 started a new conversation Create BookItem

I have a table books and a table barcodes. Any book can have multiple copies.

Book.php

class Book extends Model
{
    //
    protected $fillable = ['title', 'isbn', 'edition', 'year', 'author_id', 'photo_id', 'description'];


    public function photo(){
        return $this->belongsTo('App\Photo');
    }
    public function author(){
        return $this->belongsTo('App\Author');
    }
    public function barcode()
    {
        return $this->hasMany('App\Barcode');
    }

Barcode.php

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

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

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

in view- books-index.blade.php :


<td><a href="{{route('barcodes.create')}}">Create BookItem</a>

I want to create a new bookItem(barcode)... I have BarcodeController . Thanks!

11 Apr
3 months ago

mada72 started a new conversation UpdateOrCreate For 3 Tables

I have 3 tables;countries(id, name), cities(id, name, postal_code, country_id) and addresses(id, street,city_id) in view/addresses/edit.blade: ...

@extends('layouts.admin') @section('content')

Addresses

{!! Form::model($address,['method'=>'PATCH', 'action'=>['[email protected]', $address->id], 'files'=>true]) !!} {!! Form::label('street', 'Street:') !!} {!! Form::text('street', null, ['class'=>'form-control']) !!} {!! Form::label('city_name', 'City:') !!} {!! Form::text('city_name',$address->city->name, null, ['class'=>'form-control']) !!} {!! Form::label('city_postal_code', 'Postal Code:') !!} {!! Form::text('city_postal_code',$address->city->postal_code, null, ['class'=>'form-control']) !!} {!! Form::label('country_name', 'Country:') !!} {!! Form::text('country_name', $address->city->country->name, null, ['class'=>'form-control']) !!} {!! Form::submit('Update Address', ['class'=>'btn btn-primary']) !!} {!! Form::close() !!}

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

@stop

...

how can use updateOrCreate? ex. I want to change 'country_name' in address -if a country exist -update address, if not -create a new country and update address

09 Apr
3 months ago

mada72 started a new conversation Compare Current Date With Lastmod From Sitemap,xml Using Php

Hi,

how can i compare (difference) between current date and lastmod from sitemap.xml?

08 Apr
3 months ago

mada72 left a reply on Check Before Delete

I was thinking to make a new function beforeDelete with another form......"criminal minds" :)))

mada72 left a reply on Check Before Delete

my delete_site.php

mada72 started a new conversation Check Before Delete

Hello,

I have my sites.php ...

                <tr>
                    <td><?php echo $site->id; ?></td>
                    <td><?php echo $site->naam  ; ?>&nbsp;</td>
                    <td><?php echo $site->website; ?></td>
                    <td><?php echo $site->url; ?></td>
                    <td><?php echo $site->actief; ?></td>


                    <td>

                        <div class="px-4">

                            <a class="btn btn-danger"
                               href="delete_site.php?id=<?php echo $site->id; ?>">Delete</a>
                            <a class="btn btn-warning" href="edit_site.php?id=<?php echo $site->id; ?>">Edit</a>

                        </div>
                    </td>
                </tr>

            <?php endforeach; ?>

...

My delete_site.php

...

welkom delete pagina sites

....

and my class Site

...

class Site extends Dbobject { protected static $db_table = "sites"; protected static $db_table_fields = array('naam','website', 'url','actief');

public $id;
public $naam;
public $website;
public $url;
public $database;
public $actief;


function __construct(){

}





public static function find_all_sites(){
    return static::find_this_query("SELECT * FROM " . static::$db_table ." ORDER BY id DESC");
}


public function create(){
    global $database;
    $properties = $this->clean_properties();

    $sql = "INSERT INTO " . static::$db_table . " (" . implode(",",array_keys($properties)) . ") ";
    $sql .= "VALUES ('" . implode("','",array_values($properties)) . "')";


    if($database->query($sql)){
        $this->id = $database->the_insert_id();
        return true;
    }else{
        return false;
    }

    $database->query($sql);

}

public function update(){
    global $database;
    $properties = $this->clean_properties();
    $properties_assoc = array();

    foreach($properties as $key => $value){
        $properties_assoc[] = "{$key}='{$value}'";
    }

    $sql = "UPDATE " . static::$db_table . " SET ";
    $sql .= implode(", ", $properties_assoc);
    $sql .= " WHERE id = " .$database->escape_string($this->id);

    $database->query($sql);
    return (mysqli_affected_rows($database->connection)== 1) ? true : false;
}

function confirmDelete()
{
    return confirm("Are you sure you want to delete this?");
}

public function delete(){
    global $database;

    $sql = "DELETE FROM " . static::$db_table . " ";
    $sql .= "WHERE id= " . $database->escape_string($this->id);
    $sql .= " LIMIT 1";

    $database->query($sql);
    return (mysqli_affected_rows($database->connection)== 1) ? true : false;
}

public function save(){
    return isset($this->id) ? $this->update() : $this->create();
}

public function properties()
{
    //return get_object_vars($this);//alle variabelen van een classe worden door deze functie automatisch ingelezen
    $properties = array();
    foreach (static::$db_table_fields as $db_field) {
        if (property_exists($this, $db_field)) {
            $properties[$db_field] = $this->$db_field;
        }
    }
    return $properties;


}

}

...

Before Delete I want a message: "Are you sure?" -yes-no I don't know to write this....

06 Apr
3 months ago

mada72 left a reply on Check Input First

I tried all I have in my mind...nothing work :(