change background color in another blade using variable in laravel blade

2020-02-15 php html laravel

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' => '[email protected]']);

here is my function of the controller

public function changeColor(Request $request, $slug, $id = null, $myColor){  
        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>
    &nbsp;change color

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']}}  ; " > 


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}};" > 

You just missed the $ sign for $data variable

<div class="left" id="left_pdf" style="background:{{$data['color']}}  ; " >