vendredi 28 décembre 2018

Get multiple foreign key values and output them on view

I'm making a reservation system, this is the table that I'm currently using.I can't get the foreign key value of client payment. I already put the relationship in the models.

Booking

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class booking extends Model
{
   protected $fillable = ['clientID', 'checkInDate', 'checkOutDate', 'roomsCount', 'roomTypeID', 'adultsCount', 'childrenCount', 'amenityID', 'paymentID'];
    //public $incrementing = false;

    public function client()
    {
        return $this->belongsTo('App\Client','clientID');
    }
    public function payment()
    {
        return $this->hasOne('App\Payment');
    }
    public function amenities()
    {
        return $this->hasOne('App\Amenities');
    }

Client

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class client extends Model
{
   protected $fillable = ['fullNmae', 'firstName', 'lastName', 'phoneNumber', 'emailAddress'];
  public function booking()
  {
      return $this->hasMany('App\Booking');
  }
}

Payment

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class payment extends Model
{
   protected $fillable = ['clientID', 'paymentMethod', 'invoiceNum', 'accountName', 'amountPaid', 'datePaid', 'payment_image', 'comments'];
  public function booking()
  {
      return $this->belongsTo('App\Booking');
  }
}

I'm currently using this to access the foreign key

$bookingDetail = booking::with('client', 'payment')->get();
        return view('detail')
        ->with('bookingDetail', $bookingDetail);

view



Error I'm Getting

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'clients.id' in 'where clause' (SQL: select * from clients where clients.id in (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17))

Is this the right way to do it? or am I missing something. I'm new to laravel so I don't know if this is the right way to do it



via Chebli Mohamed

Database structure for categories, sub-categories, and services

I am using Laravel 5.5 and MySql. I cannot figure out how to relate Categories, and Sub Categories to Services without adding a subCategoryID column to the Services table.

Currently this is my table structure

Service_Categories

id, name
1, Legal Services
2, Personal Drivers

Service_Sub_Categories

id, ServiceCategoryID, name
1, 1, US Legal Services
2, 1, Europe Legal Services
3, 1, Canada Legal Services

Services

id, serviceCategoryID, name
1, 1, US Legal Services Comapny INC
2, 1, Canada Legal Services Company INC
3, 2, JSY Personal Drivers
4, 2, XYZ Personal Drivers

One service must have at least 1 Service Category but it can also have 0 or more Sub-Categories

As you can see, Personal Drivers has no sub-category, but Legal Services has many Sub-Categories. When a user selects "US Legal Services" I only want to pull those up. I could easily add a subCategoryID column to the Services table but in the future I may have sub-sub-categories. What is the best way to structure my tables?



via Chebli Mohamed

How can I update user password in Laravel 5 ?

I use Laravel 5.7.

I'm trying to update one my users password

I ran this php artisan tinker

Then

>>> bcrypt(12345);                                                                                                
=> "$2y$10$5woTm5/1w.euUliNCujmMu.oYiC.U8YnRpBHVQN/CxyKXAYB.pGiS"                                                 
>>> 

I copied the hash update that into my database

I tried to login with 12345. I can't log in.

What did I forget to do ?


Questions

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

Making datasize change to each images dimensions

I am using photo swipe and laravel and bringing in images to the photoswipe gallery by a foreach. With photoswipe you have to define data-size and i am unsure on how i set this to define the size automatically. At the moment i have it predefined and its stretching small images and shrinking bigger images. Has anyone had any experience with this and the photoswipe plugin and managed to define it automatically foreach loaded images dimensions?

Here is the code that includes the data-size definition:

   <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" >

     <a href="" itemprop="contentUrl" data-size="1200x600">
     <img src="" itemprop="thumbnail" alt="Userimage"  />
     </a>

    <figcaption itemprop="caption description">Uploaded by: , </figcaption>


   </figure>



via Chebli Mohamed

How to generate a hash password for Laravel project?

I'm using Laravel.I want to update the password of one of my users.

enter image description here

I tried went to this site : https://bcrypt-generator.com/

entered: 12345 as click Hash, then I got

$2y$12$I4R0XT4iE742UWQzAzIUf.nLQA8oQhekEl16.p4oqhqBqg5nZQLb2

I then copied the resulting hash and paste it into my database column.

enter image description here

Then try to log-in, still can't seems to log in

enter image description here


Questions

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

Sort Collection By id set

I have an array of ids that i want to sort a given column by them in the collection.

For example,

$suppliersOrder = [8,7,5,1,3,4];

$items = Items::get()->sortBy(function($model) use ($suppliersOrder) {
   return array_search($model->supplier_id, $suppliersOrder);
})->values();

This acts like ordering items as [1,3,4,5,7,8] instead of the given order. And if I try sortByDesc, likewise [8,7,5,4,3,1] but I couldn't figure out the way to actually sort them as my given array's order.

My ultimate goal is then running $items->groupBy('supplier.name') so I can have my desired order.



via Chebli Mohamed

how to perform an advanced search with scopequery

It is desired to be able to search for a specific charge, where when performing the search as the Coro Commission, all the members that belong to that position appear.

The code of sight:

@foreach ($ members as $ member)

                
                
                
                
                @if (empty ($ member-> formations-> fType))

                @else
               
               @endif

                @foreach ($ member-> charges as $ charge)

                        

                  @endforeach

            @endforeach

There is a table of parish members and positions, with many to many among them. The intermediate table has the name: cargo_membership_parish

The following is in the controller.

public function filters (Request $ request) {

  $ sector = $ request-> input ('sector');
  $ form = $ request-> formacion_id;
  $ stages = Stage :: all ();
  $ formation = Training :: all ();
  $ stage = $ request-> stage_id;
  $ charge = Charge :: all ();
  $ m_cargo = $ request-> car;
    $ members = Member_Parroquial :: orderBy ('id', 'DESC') -> sector ($ sector) -> stage ($ stage) -> training ($ form) -> get ();

  return view ('member.member_index', compact ('stages', 'formation', 'members', 'position'));

}

The SCOPEQUERY have been made in the following way:

public function scopeEtapa ($ query, $ stage) {

    if ($ stage) {

        return $ query-> where ('stage_id', 'LIKE', "% $ stage%");
    }
}

public function scopeFormation ($ query, $ form) {

    if ($ form) {
        return $ query-> where ('training_id', 'LIKE', "% $ form%");

    }
}

public function scopeCharge ($ query, $ charge) {

}

If you have an idea of ​​how to perform the scope query for charges in relation to many to many, it would be very helpful. Thank you



via Chebli Mohamed