Hi I just want to download my storage file to pdf but it show this error.
Here is my Controller
public function html(Request $request, $id=null){
if($request->isMethod('post')){
$html = $request->html;
$data = [];
if($request->hasFile('html')){
// dd($html);
$data['html'] = $request->file('html')->storeAs('all_html', time().'.blade.php');
// $data['html'] = Storage::putFile('all_html', $html);
}
$url = "storage/app/".$data['html'];
$random = 'dOC'.str::random('10');
Pdf::loadfile($url)->setPaper('a4', 'landscape')->setWarnings(false)->save(public_path('pdf/'.$random.'.pdf'));
return response()->download(public_path('pdf/'.$random.'.pdf'));
}
return view('html');
}
You need to check first in laravel storage link or not if the storage is not linked then you need to run a below command in your terminal
Storage Link command => php artisan storage:link
then check our code and run again
If this not working then you need to check your laravel storage folder permission and give them to permission
Happy Coding!!
I am using Laravel Spatie Activity Log package in my laravel application.
I could customize in each module.
public function tapActivity(Activity $activity, string $eventName)
{
$activity->description = "Category is {$eventName}. ";
$activity->os = getOS();// custom hlper
}
This problem was when I was going to save ip.
$activity->ip = $request->ip();
I think above field should be added.
But where can we get $request ?
I solved this myself.
$activity->ip = request()->ip();
This just worked. :)
I wanted to create a custom cache driver using aerospike.
I have followed the instruction given in the document:
https://laravel.com/docs/5.8/cache#adding-custom-cache-drivers
Cache::extend('aerospike', function ($app) {
$config = $app['config'];
$server = $config['cache.stores.aerospike.servers'];
$aerospike = new \Aerospike($server);
$store = new AerospikeStore($aerospike, $config['cache.prefix'], $config['cache.stores.aerospike.namespace']);
return Cache::repository($store);
});
also created the AerospikeStore file.
When run php artisan serve it always says :
In CacheManager.php line 109:
Driver [aerospike] is not supported.
I'm use Dropbox image hosting, I downloaded Dropbox's install league / flysystem-dropbox package, but when I ran the code below it crashed
Class 'Dropbox \ Client' not found.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Dropbox\Client;
use Dropbox\WriteMode;
class ExpenseController extends Controller
{
public function postExpenseAdd( Request $request ){
$Client = new Client(env('DROPBOX_TOKEN'), env('DROPBOX_SECRET'));
$file = fopen(public_path('img/admin.png'), 'rb');
$size = filesize(public_path('img/admin.png'));
$dropboxFileName = '/myphoto4.png';
$Client->uploadFile($dropboxFileName,WriteMode::add(),$file, $size);
$links['share'] = $Client->createShareableLink($dropboxFileName);
$links['view'] = $Client->createTemporaryDirectLink($dropboxFileName);
print_r($links);die;
}
}
This will not be an answer to your current question (at least not with the package you are currently working with), but this might get you back on the right track:
The league/flysystem-dropbox won't work anymore as this package uses the API v1 version of dropbox that has meanwhile been deprecated (API v1 will be completely unavailable on September 28, 2017).
Since the package is not maintaned anymore and will not receive an update to the API v2 version you should take a look at the srmklive/flysystem-dropbox-v2 package.
In short: you can run composer require srmklive/flysystem-dropbox-v2 to get started with the new version of the API.
I want my datatables to process the data on the server side, I am referencing this example.
Server Side Example
However, the server side php class "ssp.class.php" given in this example uses core php with raw sql, I can not use it directly for laravel projects. Does anyone has reference to laravel way doing datatables. I don't want to use any packages at the moment though.
UPDATED 31/01/2023
You can use syamsoul/laravel-datatable-two-ssp package..
Link here
Open CLI and enter your app directory
Run this command composer require syamsoul/laravel-datatable-two-ssp
In your controller, need to add use SoulDoit\DataTableTwo\SSP;, and you can follow the code below:
private function dtColumns()
{
return [
['label'=>'ID', 'db'=>'id', 'formatter'=>function($value){
return str_pad($value, 8, '0', STR_PAD_LEFT);
}],
['label'=>'Email', 'db'=>'email' ],
['label'=>'Username', 'db'=>'username' ],
['label'=>'Created At', 'db'=>'created_at' ],
];
}
private function dtQuery($selected_columns)
{
return \App\Models\User::select($selected_columns);
}
This is working perfectly on Laravel 8 and above.
.
.
Below is my old answer.. (21 March 2019)
You can use syamsoul/laravel-datatable-ssp package..
Link here
Open CLI and enter your app directory
Run this command composer require syamsoul/laravel-datatable-ssp
In your controller, need to add use SoulDoit\DataTable\SSP;, and you can follow the code below:
public function get(){
$dt = [
['db'=>'id', 'dt'=>0, 'formatter'=>function($value, $model){ return str_pad($value, 8, '0', STR_PAD_LEFT); }],
['db'=>'email', 'dt'=>1],
['db'=>'first_name', 'dt'=>2, 'formatter'=>function($value, $model){ return $value . ' ' . $model->last_name; }],
['db'=>'created_at', 'dt'=>3],
['db'=>'email_verified_at'],
['db'=>'last_name'], // must include this because need to re-use in 'first_name' formatter
];
$dt_obj = new SSP('\App\User', $dt);
$dt_arr = $dt_obj->getDtArr();
return response()->json($dt_arr);
}
This is working perfectly on Laravel 5.8 ... I'm not sure about the other versions.