How to print table data in Laravel 5.6?
in My Larvel 5.6 app I am working with mysql db. and in my application I have vehicle table with following columns,
vehicles,
id category number brand model
1 car 123 bmw 520d
2 van 258 ford mark
3 car 256 benz ultra
4 car 259 bmw 520d
etc
and I am going to group all models of the table and printing here as My controller,
public function modelstatic()
{
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
my printing blade file is this,
@foreach($models as $model)
{{ $model->modelname }}
@endforeach
it is printing well as
520d
mark
ultra
now I need print in-front of model name there brand name as
520d - bmw
mark - ford
ultra - benz
Then how can I do this now? I have separate Models for brand and model and still there are not relationship between Models. how can I do this, may I need relationship or may I could print brand name via vehicle table data?
php mysql laravel laravel-5 eloquent
add a comment |
in My Larvel 5.6 app I am working with mysql db. and in my application I have vehicle table with following columns,
vehicles,
id category number brand model
1 car 123 bmw 520d
2 van 258 ford mark
3 car 256 benz ultra
4 car 259 bmw 520d
etc
and I am going to group all models of the table and printing here as My controller,
public function modelstatic()
{
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
my printing blade file is this,
@foreach($models as $model)
{{ $model->modelname }}
@endforeach
it is printing well as
520d
mark
ultra
now I need print in-front of model name there brand name as
520d - bmw
mark - ford
ultra - benz
Then how can I do this now? I have separate Models for brand and model and still there are not relationship between Models. how can I do this, may I need relationship or may I could print brand name via vehicle table data?
php mysql laravel laravel-5 eloquent
add a comment |
in My Larvel 5.6 app I am working with mysql db. and in my application I have vehicle table with following columns,
vehicles,
id category number brand model
1 car 123 bmw 520d
2 van 258 ford mark
3 car 256 benz ultra
4 car 259 bmw 520d
etc
and I am going to group all models of the table and printing here as My controller,
public function modelstatic()
{
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
my printing blade file is this,
@foreach($models as $model)
{{ $model->modelname }}
@endforeach
it is printing well as
520d
mark
ultra
now I need print in-front of model name there brand name as
520d - bmw
mark - ford
ultra - benz
Then how can I do this now? I have separate Models for brand and model and still there are not relationship between Models. how can I do this, may I need relationship or may I could print brand name via vehicle table data?
php mysql laravel laravel-5 eloquent
in My Larvel 5.6 app I am working with mysql db. and in my application I have vehicle table with following columns,
vehicles,
id category number brand model
1 car 123 bmw 520d
2 van 258 ford mark
3 car 256 benz ultra
4 car 259 bmw 520d
etc
and I am going to group all models of the table and printing here as My controller,
public function modelstatic()
{
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
my printing blade file is this,
@foreach($models as $model)
{{ $model->modelname }}
@endforeach
it is printing well as
520d
mark
ultra
now I need print in-front of model name there brand name as
520d - bmw
mark - ford
ultra - benz
Then how can I do this now? I have separate Models for brand and model and still there are not relationship between Models. how can I do this, may I need relationship or may I could print brand name via vehicle table data?
php mysql laravel laravel-5 eloquent
php mysql laravel laravel-5 eloquent
edited Nov 18 '18 at 15:50
Steve Nosse
213111
213111
asked Nov 18 '18 at 11:36
FernandoFernando
163114
163114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The same way you select the model name column, you must also select the brand column, and then print the model with his brand name.
Try this :
In your controller :
public function modelstatic(){
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', 'brand', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
and in your view :
@foreach($models as $model)
{{ $model->modelname }} - {{ $model->brand }}
@endforeach
Hope my answer helps!
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360418%2fhow-to-print-table-data-in-laravel-5-6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The same way you select the model name column, you must also select the brand column, and then print the model with his brand name.
Try this :
In your controller :
public function modelstatic(){
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', 'brand', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
and in your view :
@foreach($models as $model)
{{ $model->modelname }} - {{ $model->brand }}
@endforeach
Hope my answer helps!
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
add a comment |
The same way you select the model name column, you must also select the brand column, and then print the model with his brand name.
Try this :
In your controller :
public function modelstatic(){
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', 'brand', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
and in your view :
@foreach($models as $model)
{{ $model->modelname }} - {{ $model->brand }}
@endforeach
Hope my answer helps!
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
add a comment |
The same way you select the model name column, you must also select the brand column, and then print the model with his brand name.
Try this :
In your controller :
public function modelstatic(){
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', 'brand', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
and in your view :
@foreach($models as $model)
{{ $model->modelname }} - {{ $model->brand }}
@endforeach
Hope my answer helps!
The same way you select the model name column, you must also select the brand column, and then print the model with his brand name.
Try this :
In your controller :
public function modelstatic(){
$models = Vehicle::groupBy('modelname')->select('id', 'modelname', 'brand', DB::raw('COUNT(*) as cnt'))->get();
return view('modelreports.modelstatic')->withModels($models);
}
and in your view :
@foreach($models as $model)
{{ $model->modelname }} - {{ $model->brand }}
@endforeach
Hope my answer helps!
answered Nov 18 '18 at 12:04
Steve NosseSteve Nosse
213111
213111
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
add a comment |
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
well, it is working fine you save my day all
– Fernando
Nov 18 '18 at 12:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360418%2fhow-to-print-table-data-in-laravel-5-6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown