Thursday, 21 September 2023
laravel unique validation, except self , ignore self or current row
Wednesday, 20 September 2023
laravel make image thumbnail intervantion
Wednesday, 6 September 2023
laravel react inertia, show images
If you want to define the base URL for serving images from the `public` folder in a central place so that you can easily update it if needed, you can create a configuration file or a JavaScript variable to store the base URL. Here's how you can do that:
**Option 1: Define a JavaScript variable:**
In your Laravel project, you can create a JavaScript file (e.g., `config.js`) where you define the base URL for serving images. For example:
```javascript
// config.js
const IMAGE_BASE_URL = '/images/';
export default IMAGE_BASE_URL;
```
Then, in your React components, you can import this variable and use it to construct image URLs:
```jsx
import React from 'react';
import IMAGE_BASE_URL from './config'; // Adjust the import path accordingly
function ImageDisplay() {
// Construct image URL using the base URL
const imageUrl = `${IMAGE_BASE_URL}image.jpg`;
return (
<div>
<img src={imageUrl} alt="Image" />
</div>
);
}
export default ImageDisplay;
```
This way, you can easily change the base URL for images by updating the `config.js` file.
**Option 2: Define a configuration file in Laravel:**
Alternatively, you can define a configuration variable in Laravel to store the base URL for serving images. Here's how you can do that:
1. Create a custom configuration file in Laravel by running the following command:
```bash
php artisan make:config image
```
This will create a new configuration file at `config/image.php`.
2. In the `config/image.php` file, define the base URL for serving images:
```php
<?php
return [
'base_url' => '/images/',
];
```
3. In your Laravel application, you can access this configuration value using the `config()` function and pass it to your Inertia views:
```php
// In your controller
use Illuminate\Support\Facades\Config;
public function index()
{
$imageBaseUrl = Config::get('image.base_url');
return inertia('YourViewName', [
'imageBaseUrl' => $imageBaseUrl,
]);
}
```
4. In your Inertia.js view component, you can then use this `imageBaseUrl` to construct image URLs:
```jsx
import React from 'react';
import { usePage } from '@inertiajs/inertia-react';
function ImageDisplay() {
const { imageBaseUrl } = usePage();
// Construct image URL using the base URL
const imageUrl = `${imageBaseUrl}image.jpg`;
return (
<div>
<img src={imageUrl} alt="Image" />
</div>
);
}
export default ImageDisplay;
```
This approach allows you to configure the base URL for serving images directly in your Laravel configuration files, making it easy to manage and update.
Within HandleInertiaRequest middleware
Laravel Export data to csv
use Illuminate\Http\Response; // Define a function to export data to CSV function exportToCSV($exportData, $columns) { $filename = ...
-
download source code.zip from below link https://github.com/fideloper/TrustedProxy/releases extract the zip open vendor folder create a ne...
-
if ( $request -> hasfile ( 'project_nda' )) { if ( $SalesClosure -> project_nda != "" &...
-
1) Install Laravel excel in laravel existing project https://docs.laravel-excel.com/3.1/getting-started/installation.html 2)Create new clas...