Tag Archives: laravel

How to export specific attributes from model in Maatwebsite Excel in Laravel 5.1

Questions: I want to pick some attributes from model in Laravel using Maatwebsite Excel export (not the full model attributes). I’m doing something like this, it works fine but gives full attributes of model: public function exportUserData(){ ob_end_clean(); ob_start(); $user= User::where(‘type’, ‘=’, ‘writers’)->get()->toArray(); Excel::create(‘users’, function($excel) use($user) { $excel->sheet(‘Sheet 1’, function($sheet) use($user) { $sheet->fromArray($user); }); })->download(‘xlsx’);… Read More »

Laravel-Excel (MaatWebSite) takes to long reading

Questions: I dont know what im doing wrong, or maybe its something normal. I have to load and “read” a excell with about 12000 rows. I use this code for that. Excel::selectSheetsByIndex(0)->load($path.$fileName, function ($reader) { $reader->each(function($row){ Log::info(‘$row’); }); }); As you can see, there is nothing heavy wich could make the read so slow. I… Read More »

Laravel 5.5 Export EXCEL

Questions: i try to export same data in excel format usinf Maatwebsite/Laravel-Excel package,it work fine, but i game a problem to make same style for the first row of the excel document: This is my code : Excel::create(‘Adressbook contacts’, function($excel) use ($sheetArray,$groupe){ $excel->sheet($groupe->title, function($sheet) use ($sheetArray) { $sheet->fromArray($sheetArray); $sheet->row(1, function($row) { $row->setBackground(‘#ff6600’); $row->setFontColor(‘#ffffff’); $row->setValignment(‘center’); });… Read More »

Laravel excel passing a view

Questions: I’m trying to export data to excel and I can’t seem to make it work. I am using: http://www.maatwebsite.nl/laravel-excel/docs and I’m following the docs as much as I can. So I have this view which I’m trying to get in excel. The docs are telling me: Loading a view for a single sheet $sheet->loadView(‘folder.view’);… Read More »

Laravel Excel Export set value to cell?

Questions: I have used maatwebsite excel library for Import and Exporting data. i want to set cell wise data like. A B C D E F 1 heading1 heading2 heading3 heading4 heading5 heading6 2 data1 data2 data3 data4 data5 data6 3 data12 data22 data32 data42 data52 data62 4 data23 data33 data43 data53 5 data34 data44… Read More »

laravel excel get headers and maatwebsite

Questions: I want to get only my excel first column that will be column name. I am using this code Excel::load($request->file, function ($reader) use($request) { $torarray=$reader->toArray(); $line0 = $torarray[0]; $headers = array_keys($line0); $excel_header=$headers; }); Sometimes it works but some times not work. when not work with some files the i write below that and works… Read More »

raw SQL to laravel query

Questions: Can anybody please help me to write a DB query version of the SQL statement below. I need a little help around the select statement and the partitioned joins. I have managed to do this so far. $query = DB::table(raw(‘SapakInAdminOrder a’)) ->select(raw(‘a.*’)) ->leftJoin(raw(‘currency cu’), ‘a.currency’, ‘=’, ‘cu.id’) ->leftJoin(raw(‘moodboards m’), ‘a.orderMoodboardID’, ‘=’, ‘m.id’) ->join(raw(‘clients b’),… Read More »

laravel eloquent integers returned as strings in mssql

Questions: i am running mssql2008 with laravel 5.0 and every time i retrieve data from DB seems like everything is been returned as string no matter which format i have it stored on the database. { id: “1”, name: “This is crazy”, owner_id: null, is_local: “0”, vessel_type_id: “3”, registration_number: “34535”, gross_register_tonnage: “34”, year_built: “3453”, status:… Read More »

Laravel-5 how to populate select box from database with id value and name value

Questions: I want to create a select box like the one below using illuminate\html : <select> <option value=”$item->id”>$item->name</option> <option value=”$item->id”>$item->name</option> </select> In my controller I tried this: public function create() { $items = Items::all([‘id’, ‘name’]); return view(‘prices.create’, compact(‘id’, ‘items’)); } And in my view this: <div class=”form-group”> {!! Form::Label(‘item’, ‘Item:’) !!} {!! Form::select(‘item_id’, $items, null,… Read More »

Using CSS in Laravel views?

Questions: I’ve just began learning Laravel, and can do the basics of a controller and routing. My OS is Mac OS X Lion, and it’s on a MAMP server. My code from routes.php: Route::get(‘/’, function() { return View::make(‘home.index’); }); Route::get(‘businesses’, function() { return View::make(‘businesses.index’); }); Route::get(‘testing’, function() { return View::make(‘testing.index’); }); Route::get(‘hello’, function() { return… Read More »