Reputation: 31
I'm working with Laravel right now and can't figure out how I can apply different background colors on page that i want ..
Actually, I want to change the background of my page which I convert to PDF
here is my route
Route::get('/form/{slug}/pdf/{id}/{color?}', ['as' => 'generate.pdfColor', 'uses' => 'OriginController@changeColor']);
here is my function of the controller
public function changeColor(Request $request, $slug, $id = null, $myColor){
$colors=[
1=> ['color'=>'#1e90ff'],
2=> ['color'=>'#2ecc71'],
3=> ['color'=>'#e84118'],
4=> ['color'=>'#222D32'],
5=> ['color'=>'#ffcccc'],
6=> ['color'=>'#910000']
];
return view('layouts.modules.student_pdf',['data'=>$colors[$myColor]]);
}
here is my link to sending parameter of the color
in this example 1 is (#1e90ff
)
<a target="_blank" href='<?php echo e(route('generate.pdfColor', ['slug' => 'student', 'id' => '56', 'color' => '1'])); ?>'>
<i class='fa fa-file-pdf-o 2x avatar'></i>
change color
</a>
and this my page cv_pdf.blade.php
that i want to change the bg
<!-- left -->
<div class="left" id="left_pdf" style="background:{{data['color']}} ; " >
..............
</div>
Upvotes: 0
Views: 2785
Reputation: 4813
You just missed the $
sign for $data
variable
//Fix
<div class="left" id="left_pdf" style="background:{{$data['color']}} ; " >
Upvotes: 2
Reputation: 2677
change function changeColor
like below:
public function changeColor(Request $request, $slug, $id = null, $myColor){
//just change return line like below
return view('layouts.modules.student_pdf')->with(['color' => $colors[$myColor]['color']]);
}
and in page_cv_pdf.blade.php
do as follows:
<div class="left" id="left_pdf" style="background-color:{{$color}};" >
..............
</div>
Upvotes: 0