lundi 27 juin 2016

Laravel 5,Relationships,4 tables

I have next tables:

case

no (primary key)

case_providers

case_no (id) providers_code (id)

user_cards

providers_code (id) country (id) city

user_conuntries

country (id) name (varchar)

user_cities

city(id) country(id) name (varchar)

How i can populate this form:

 @foreach ($providers as $provider)
<div class="row">
    <div class="form-group col-xs-3 col-md-3">
        <label for="policy_no">Code:</label>                       
        <input type="text" class="form-control" name="providers[]" required value="">
    </div>
    <div class="form-group col-xs-2 col-md-2">
        <label for="policy_id">Country:</label>                          
        <input type="text" class="form-control" value="" disabled>
    </div>
    <div class="form-group col-xs-2 col-md-2">
        <label for="policy_id">City:</label>                          
        <input type="text" class="form-control" value="" disabled>
    </div>
</div>
@endforeach

? Now i have next code:

class CaseController extends Controller {
        public function show($id) {
                $case = \App\Cases::where('no', $id)->first();
                .....
                $providers = $case::find($id)->providers;
                return view('case.case', compact('case', 'country', 'status', 'type', 'all_clients', 'providers'));
            }
        }
    class Cases extends Model {

        const UPDATED_AT = 'edit_date';
        const CREATED_AT = 'crt_date';

        protected $primaryKey = 'no';
        //protected $fillable = ['surname', 'email', 'password', 'comments', 'admin_role', 'active_until', 'policy_detail'];
        protected $guarded = ['no'];
        protected $table = 'assist';

        public function providers() {
            return $this->hasMany('App\CaseProviders','case_no');
        }

    }
    class CaseProviders extends Model
    {
        //
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire