Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

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

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:

  1. composer require reliese/laravel
  2. Add the service provider to your config/app.php file, Reliese\Coders\CodersServiceProvider::class
  3. Publish the config file with php artisan vendor:publish --tag=reliese-models
  4. And finally issue the command: php artisan code:models

Hope this helps :)

0

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..

Last updated 7 years ago.
0

CristianLlanos said:

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:

  1. composer require reliese/laravel
  2. Add the service provider to your config/app.php file, Reliese\Coders\CodersServiceProvider::class
  3. Publish the config file with php artisan vendor:publish --tag=reliese-models
  4. And finally issue the command: php artisan code:models

Hope 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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.