Viblo
  • Posts
  • Questions
  • Discussions
Announcements
No announcement yet.
All Announcements

Nguyễn Hữu Sử

@huusu1996

Report
  • Posts
  • Series
  • Questions
  • Answers
  • Clips
  • Followings
  • Followers
  • Tags
  • Reputations
  • Communication

Validation input array laravel

Nguyễn Hữu Sử
Answered Nov 20th, 2020 3:29 AM

Bác thử thay lại các select xem sao

<select name="question[{{ $id }}]">
+3

Xử lý dữ liệu trong ajax

Nguyễn Hữu Sử
Answered Nov 15th, 2020 8:59 AM

Bạn tìm hiểu thêm từ khóa jquery event dynamic element xem sao nhé, trường hợp của bạn thử sửa như sau xem có giải quyết được bài toán của bạn không 🤔

<script type="text/javascript"> 
     $(document).on('click', '#fTangDiem', function() {
			$("#btnTangDiem", this)
			  .html("Đang xử lý...")
			  .attr("disabled", "disabled");
			return true;
		});
</script>
+1

Laravel API và setInterval AJAX

Nguyễn Hữu Sử
Answered Oct 25th, 2020 6:22 AM

Em đoán do lần đầu $.ajaxSetup() được gọi do khi load trang. Từ lần thứ 2 nó không bắt được event load trang nên không gọi vào hàm này nữa dẫn đến lỗi csrf token mismatch 😜😜

Bác thử xử lí theo kiểu set cái token vào data khi call ajax xem sao

    $.ajax({
        url: "savechange",
        method: "PUT",
        data: {
            id: 123332423,
            "_token": $('meta[name="csrf-token"]').attr('content')
        },
    });
0

Công nghệ được sử dụng trong Viblo là gì các bác!

Nguyễn Hữu Sử
Answered Sep 29th, 2020 10:58 AM

Đúng đó bạn ơi, trước mình xem một video anh Thắng có nói qua về cách viblo đang vận hành thì phải Screenshot from 2020-09-29 17-59-12.png

Link: https://viblo.asia/p/viblo-deployment-day-web-development-best-practices-Eb85oJGWl2G

0

Tại sao từ Eloquent có thể call được function định nghĩa cho query builder?

Nguyễn Hữu Sử
Answered Aug 20th, 2020 2:43 AM

Nguồn: https://stackoverflow.com/questions/34530371/laravel-5-model-object-could-call-builder-method-how-does-laravel-do-that

This is because Eloquent usesIlluminate\Database\Query\Builder behind the scenes and you can find all those methods in this Builder class. When you run function that does not exist in Users model in this case, magic method __call(https://www.php.net/manual/en/language.oop5.overloading.php#object.call) is used:

public function __call($method, $parameters)
{
    if (in_array($method, ['increment', 'decrement'])) {
        return call_user_func_array([$this, $method], $parameters);
    }

    $query = $this->newQuery();

    return call_user_func_array([$query, $method], $parameters);
}

as you see in this method newQuery method is executed. And when you look at this method definitions you can see here:

public function newQuery()
{
    $builder = $this->newQueryWithoutScopes();

    foreach ($this->getGlobalScopes() as $identifier => $scope) {
        $builder->withGlobalScope($identifier, $scope);
    }

    return $builder;
}

and further, when you look at newQueryWithoutScopes you'll see there:

$builder = $this->newEloquentBuilder(
        $this->newBaseQueryBuilder()
);

and this newEloquentBuilder method returns new Builder($query); so it's an Illuminate\Database\Query\Builder object

+1

Config APP_URL trong .env laravel không nhận @@????

Nguyễn Hữu Sử
Answered Aug 4th, 2020 1:45 PM

Phần gửi gửi mail bạn có dùng queue không ? Nếu có thử restart queue chạy

php artisan queue:restart

Rồi gửi mail lại xem sao

+1

Các pro Laravel cho em hỏi chút về Query Builder với ạ

Nguyễn Hữu Sử
Answered Jul 16th, 2020 6:58 AM

Bạn có thể sử dụng một class như là repository. Ví dụ như thế này, đảm bảo không cần extend Models

namespace App\Repo;

use Illuminate\Database\Connection;
use Illuminate\Support\Collection;

class StreetRepository implements StreetRepositoryInterface
{
    /**
     * @var \Illuminate\Database\Connection
     */
    protected $db;

    /**
     * StreetRepository constructor.
     *
     * @param \Illuminate\Database\Connection $db
     */
    public function __construct(Connection $db)
    {
        $this->db = $db;
    }

    /**
     * @return \Illuminate\Database\Query\Builder
     */
    protected function query()
    {
        return $this->db->table('streets');
    }

    public function paginateList($page = null, array $columns = ['*'], $perPage = StreetRepositoryInterface::DEFAULT_LIMIT)
    {
        return $this->query()
            ->paginate($perPage, $columns, 'page', $page);
    }
....
0

Sử dụng toast trong laravel

Nguyễn Hữu Sử
Answered May 8th, 2020 8:15 AM
toastr.clear();

Sau mỗi lần thực thi toast.success hoặc toast.info bạn ơi

+1

Xin hỏi về get value 0 từ form trong laravel

Nguyễn Hữu Sử
Answered May 8th, 2020 1:08 AM

Trên server xử lí, nếu value có giá trị bằng [] thì gán lại cho nó bằng 0 là được mà bạn =))

0

Validation trong Laravel

Nguyễn Hữu Sử
Answered May 5th, 2020 2:14 AM
  1. Tạo 1 rule để validate số tiền trong ví và trong DB
php artisan make:rule CheckMaxMoney

Trong class CheckMaxMoney ở thư mục app/rule

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class CheckMaxMoney implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
         $money = Lấy dữ liệu money của người dùng trong DB;
         if($value < $money) {
            return true; // Pass validate
        }
        return false; // Không pass validate
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'Số tiền trong ví nhỏ hơn số tiền chuyển  .';
    }

}
  1. Tạo 1 form validate để khi có request chuyển tiền
php artisan make:request TransactionRequest

Trong class TransactionRequest xử lí

<?php

namespace App\Http\Requests\Form;

use Illuminate\Foundation\Http\FormRequest;
use App\Rule\CheckMaxMoney;

class TransactionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
             'monney' => new CheckMaxMoney($this->money)
        ];
    }
}

Có thể idea đến triển khai sẽ gặp vài lỗi nhưng tư tưởng là vậy. Chúc bạn may mắn, mà chắc bạn đang dùng laravel nhỉ :3

Tham khảo thêm : https://laravel.com/docs/7.x/validation#using-rule-objects

+5

Tìm hiểu về queues và Task Scheduling

Nguyễn Hữu Sử
Answered Apr 26th, 2020 12:21 AM

Vì câu hỏi của bạn chưa rõ ràng về cấu hình queue ra sao nên mình cứ trả lời theo cách mình vẫn hay làm vậy. Thường thì mọi người hay cấu hình lưu job ở database hoặc redis. Mình thì hay chọn redis nên mình setup như nhau.

  • Cài đặt redis
sudo apt-get update
sudo apt-get install redis-server
  • Kiểm tra xem nó đã được cài đặt hay chưa ? Nếu output là PONG thì coi như cài đặt thành công
redis-cli
127.0.0.1:6379> ping
//Output
PONG

  • Tiếp theo là cài đặt predis để Laravel thao tác với redis
composer require predis/predis
  • Cấu hình .env trong Laravel
QUEUE_DRIVER=redis

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=predis
  • Chạy câu lệnh để lằng nghe các job trong queue ở một terminal và giữ nguyên chúng trong quá trình làm việc ở local.
php artisan queue:restart // Cẩn thận nên mình khởi động lại queue 
php artisan queue:work redis
  • Khi có 1 job được lắng nghe trên terminal sẽ hiển thị như sau. Trường này là job của mình đang bị fail
SUN-ASTERISK\nguyen.huu.[email protected]-pc:~/Framgia-project/manager_shirt$ php artisan queue:work redis
[2020-04-26 07:16:16][pufXwWA6lXRXesqc5yGrJVelYBRQtYr7] Processing: App\Jobs\ProcessGetDataSheet
[2020-04-26 07:18:37][pufXwWA6lXRXesqc5yGrJVelYBRQtYr7] Failed:     App\Jobs\ProcessGetDataSheet
  • Khi queue lỗi thì theo config mặc định của file config/queue.php sẽ lưu vào bảng fail_jobs như sau
    'failed' => [
        'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],

Chúc bạn may mắn 😄

+1

PHP- tăng thời gian đợi khi load website

Nguyễn Hữu Sử
Answered Mar 24th, 2020 4:19 AM

Bonus nếu bạn dùng Laravel bạn có thể khai báo luôn ở constructor của class

public function __construct()
{
    set_time_limit(8000000);
}
+1

Service hỗ trợ gọi video

Nguyễn Hữu Sử
Answered Mar 9th, 2020 5:25 AM

Service khá ngon, bạn có thể tham khảo. Chúc bạn thành công https://stringee.com/vi/video-conference

+1

Hỏi về cách note lại những kiến thức mình biết, nhận được hằng ngày

Nguyễn Hữu Sử
Answered Nov 15th, 2019 2:30 AM

From G4 with love 😍 Screen Shot 2019-11-15 at 9.29.43 AM.png

+3

hỏi trang kenh14

Nguyễn Hữu Sử
Answered Nov 13th, 2019 4:17 AM

Đây là toàn bộ công nghệ mà site kenh14.vn đang sửa dụng bạn nhé, lướt qua 1 chút xem nào

Backend: ASP.NET

Frontend: Jquery thần thánh

Server: Nginx

Screen Shot 2019-11-13 at 11.08.59 AM.png

Quay lại câu hỏi của bạn. Trước tiên tìm hiểu qua định nghĩa nhé.

Bootstrap là gì?

Bootstrap là một framework cho phép thiết kế website reponsive nhanh hơn và dễ dàng hơn Bootstrap là bao gồm các HTML templates, CSS templates và Javascript tao ra những cái cơ bản có sẵn như: typography, forms, buttons, tables, navigation, modals, image carousels và nhiều thứ khác. Trong bootstrap có thêm các plugin Javascript trong nó. Giúp cho việc thiết kế reponsive của bạn dễ dàng hơn và nhanh chóng hơn.

Suy luận 1:

Mình check <head> của site không thấy key bootstrap nào cả, vậy là không dùng Bootstrap rồi

Chưa thể kết luận vội vì có thể dev bên đó đã mix file bootstrap nó vào file css nào đó

Suy luận 2:

F12 tìm đến tab element tìm các class thần thánh của Bootstrap như btn btn-succces, row . . . nhưng cũng không thấy có

Suy luận 3:

Thu nhỏ site kenh14 về định dạng mobile, tablet thấy phần menu thiết kế khá ẩu khi không col lại theo từng màn hình được.

Kết luận : 80% là không dùng Bootstrap bạn nhé

+6

Lỗi khi vào trang viblo

Nguyễn Hữu Sử
Answered Oct 25th, 2019 4:43 AM

Bạn thử F12 lên xoá hết cookie, storage đi rồi đăng nhập lại xem 😄

+1

Convert HTML/CSS/JS to VueJS Component

Nguyễn Hữu Sử
Answered Oct 25th, 2019 3:40 AM

Nếu bạn viết Vuejs trong project laravel bạn có thể mở file theo đường dẫn resources/js/bootstrap.js

Ở đây bạn có thể thấy Laravel đã require sẵn jquery và một số thư viện js khác. Việc của bạn sẽ là tìm các thư viện publish trên npm packages và require vào đây

Ví dụ trong trường hợp project của mình mình đã require thư viện admin-lte

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
    require('admin-lte');
    require('jquery-contextmenu');
} catch (e) {}

Tham khảo thêm tại : https://viblo.asia/p/frontend-install-admin-lte-as-a-node-dependency-gDVK2R9eKLj

+2

Lấy 2 mảng con trong mảng - Laravel

Nguyễn Hữu Sử
Answered Oct 15th, 2019 6:52 AM
$this->whereHas('bills', function($query) {
    $query->orderBy('id', 'DESC')->limit(2);
})->with('bills')->orderBy('id', 'ASC')->limit(10)->get();

Không biết đúng ý của bạn chưa

+1

Viblo có thể làm cái cúp cho hot authors của tháng được không ?

Nguyễn Hữu Sử
Answered Oct 10th, 2019 4:35 AM
Thi thoảng đọc được mấy bài đấy mình hay tự hỏi: "Làm sao để viết được những bài viblo tuyệt vời vậy nhỉ ?".

2 tip nhỏ em hay đặt ra để tạo ra một bài report hay.

  1. Luôn đặt target bài viết của mình phải được editor's choise Khi có target rồi sẽ dẫn tới hành động ✌️
  2. Viết bài report trước kì deadline, vì khi có deadline mình hay đi dịch để có bài. Vì thế em luôn chủ động viết trước deadline 5-10 ngày, mình trau chuốt bài viết của mình hơn/

Chúc anh có nhiều bài viết hay hơn nữa.

+3

Lỗi khi chạy laravel sử dụng docker compose

Nguyễn Hữu Sử
Answered Oct 9th, 2019 6:45 AM

B1: docker ps (list all container docker)

B2: Bash vào workspace của laravel

docker exec -it ten_workspace bash

B3: cấp quyền ghi cho thư mục storage, để cho nhanh mình thường dùng lệnh

sudo chmod -R 777 storage
+1
  • 1
  • 2

Total post views

55.2K

Reputations

3984

Following tags

9

Following users

21

Followers

121

Posts

27

Clips

49

Total questions

2

Total answers

34

Badges


Viblo MayFest 2020 Badge

Technical skills


PHP Node.js Laravel VueJS

Organization


Avatar
PHP Education Team
7 41 239
Avatar
Avengers Group
55 35 99

Posts tendency


Resources

  • Posts
  • Organizations
  • Questions
  • Tags
  • Videos
  • Authors
  • Discussions
  • Recommend System
  • Tools
  • Machine Learning
  • System Status

Services

  • Viblo CV Viblo Code
  • Viblo CV Viblo CV
  • Viblo CTF Viblo CTF
  • Viblo Learning Viblo Learning

Mobile App

Get it on Google Play Download on the App Store
QR code

Links

  • Atom Icon

© 2021 Viblo. All rights reserved.

  • About Us
  • Feedback
  • Help
  • FAQs
  • RSS
  • Terms
  • DMCA.com Protection Status