Posts

Showing posts with the label laravel

Permission issue after upload project

If Permission issue after upload project then type below command   sudo chown -R www-data:www-data /var/www/api.connect21.in/storage /var/www/api.connect21.in/bootstrap/cache

Name Validation in Laravel

  Alphabetic and Spaces Names often contain spaces (e.g., first and last names). To allow alphabetic characters and spaces: $request->validate([ 'name' => 'required|regex:/^[a-zA-Z\s]*$/', ]); Including Dashes and Apostrophes Some names might include dashes or apostrophes. You can adjust the regular expression to allow these: $request->validate([ 'name' => 'required|regex:/^[a-zA-Z\s\'\-]*$/', ]);

Get Value for Posted json Data in Laravel

To directly access a nested value like id inside a user object from the JSON payload in a Laravel controller, you can use dot notation with the input method of the Laravel Request object. This allows you to navigate through nested data structures easily. Assuming you have the following JSON structure being sent to your Laravel application: { "id": 19736, "user": { "id": 5, // other user attributes... }, // other root level attributes... } Route::post('/your-endpoint', 'App\Http\Controllers\YourController@handlePostRequest'); namespace App\Http\Controllers; use Illuminate\Http\Request; class YourController extends Controller {     public function handlePostRequest(Request $request)     {         // Directly access the nested 'id' inside 'user'         $userId = $request->input('user.id');         // Now you can use $userId for your logic, e.g., find the user in the database   ...