What do you mean doesn't work? - error?
Have you tried echoing out your SQL (echo $obj->toSql())
return $this->hasMany('App\model\transHistory', 'trans_key', 'receipt_no');
If you are using MySQL and Laravel 5.1 or above you can use php artisan code:models from this package reliese/laravel. It scans your database and creates all models for you, including relationships (as long as they are defined as foreign keys). If you need something more specific, you can customize its config file. All you need to do is:
composer require reliese/laravelconfig/app.php file, Reliese\Coders\CodersServiceProvider::classphp artisan vendor:publish --tag=reliese-modelsphp artisan code:modelsHope this helps :)
elite123 said:
What do you mean doesn't work? - error?
Have you tried echoing out your SQL (echo $obj->toSql())
return $this->hasMany('App\model\transHistory', 'trans_key', 'receipt_no');
Thank you anyway, i have tried that way and doesn't work, laravel always connect transHistory.trans_no to salesReceipt.id by default, even when i write exactly as your suggestion. But thankyou anyway..
CristianLlanos said:
If you are using MySQL and Laravel 5.1 or above you can use
php artisan code:modelsfrom this package reliese/laravel. It scans your database and creates all models for you, including relationships (as long as they are defined as foreign keys). If you need something more specific, you can customize its config file. All you need to do is:
composer require reliese/laravel- Add the service provider to your
config/app.phpfile,Reliese\Coders\CodersServiceProvider::class- Publish the config file with
php artisan vendor:publish --tag=reliese-models- And finally issue the command:
php artisan code:modelsHope this helps :)
thank you, i will try this, maybe i can mimic functions or model relationship generated by laravel and re-use it. and this is really helpful for me. thank you very much
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.