Laravel Tip : String Transform

use Illuminate\Support\Str;

Route::get("api/v2/test-transformations",function(Request $request){

    // 📌  Example : Hoa Nguyen Coder
    $string  = Str::of($request->input_text);

    $camel = $string->camel(); // ⚡ "hoaNguyenCoder"

    $slug = $string->slug(); // ⚡ "hoa-nguyen-coder"

    $snake = $string->snake(); // ⚡ "hoa_nguyen_coder"

    $studly = $string->studly(); // ⚡ "HoaNguyenCoder"

    $title = $string->title(); // ⚡ "Hoa Nguyen Coder"

    $key = $string->slug(''); // ⚡ "hoanguyencoder"

    $constant = $string->slug('_')->upper(); // ⚡ "HOA_NGUYEN_CODER"

    return Response()->json(["success"=>true,"data"=>json_encode([
        'string' => $string,
        'camel' => $camel,
        'slug' => $slug,
        'snake' => $snake,
        'studly' => $studly,
        'title' => $title,
        'key' => $key,
        'constant' => $constant

    ])]);

});

 

Bài Viết Liên Quan

Messsage

Nếu bạn thích chia sẻ của tôi, đừng quên nhấn nút !ĐĂNG KÝ