laravel-5.3

Validate an array of integers

我们两清 提交于 2019-12-07 05:49:44
问题 Given an array of integers: [1, 2, 3, 4, ...] How can I use the validator to check if each of these exists in a table? Possible without a foreach loop? $validator = Validator::make($request->all(), [ 'array' => 'required|exists:users,id' ]); 回答1: Your validation as written should work. If the exists validation is used with an array, it will automatically use where in for the exists query. So, given your validation as you have written, the validation will get the count of the users records

HTML Tags containing Vue.js v-if and v-for directives flash at loading

北慕城南 提交于 2019-12-07 05:40:39
问题 I use Vue.js to send data to a basic and very simple API that subscribes an e-mail address to a newsletter via the form below and to display some messages (state and errors). I use in particularly the directives v-if and v-for to display the errors and two messages. The thing is when the page is loading, those two paragraph elements and the unordered list element "flash" until the page is fully loaded or until the Vue.js instance is mounted. Am I doing it wrong? Is this a common issue? Is

How to use web and api guards at the same time in Laravel?

送分小仙女□ 提交于 2019-12-06 17:23:53
问题 I have build application with two parts: RESTful part for mobiles and web. How can I use web/api guards at the same time? That I can register users with stadart web form, and accept request like as Restful? 回答1: Protect whatever routes are for your api with auth:api middleware Route::group(['middleware' => ['auth:api']], function(){ //protected routes for API }); We must make sure that your users table has an api_token column: php artisan make:migration alter_users_table_add_api_token_column

Laravel 5.3 Storage::put creates a directory with the file name

萝らか妹 提交于 2019-12-06 17:12:30
问题 I'm using Laravel's file storage functionality to save a file: public function dataPost(Request $request) { $fileInForm = 'doc'; if ($request->hasFile($fileInForm)) { $file = $request->file($fileInForm); if ($file->isValid()) { // Filename is hashed filename + part of timestamp $hashedName = hash_file('md5', $file->path()); $timestamp = microtime() * 1000000; $newFilename = $hashedName . $timestamp . '.' . $file->getClientOriginalExtension(); Storage::disk('local')->put($newFilename, $file);

How to remove quotes from SQL query Laravel?

让人想犯罪 __ 提交于 2019-12-06 16:54:32
I have the following query: $this->data = \DB::table('months')->select(DB::raw("months.id, COUNT(transactions.id) as total")) ->leftJoin('transactions', function($join) { $join->on('months.id', '=', DB::raw('MONTH(created_at)')) ->on('transactions.doctor_id', '=', $this->user_id); }) ->groupBy('months.id') ->get(); It involks an error on line ->on('transactions.doctor_id', '=', $this->user_id); . It added single quotes for variable $this->user_id . How to avoid this eroros: SQLSTATE[42S22]: Column not found: 1054 Unknown column '2' in 'on clause' (SQL: select months.id, COUNT(clients.id) as

Auth::attempt() is not working in Laravel 5.5

谁说胖子不能爱 提交于 2019-12-06 13:37:30
My registration form is working and it store users to db but when user login then Auth::attempt() return false. Here is my code for login. I store the password in db in sha1 encription. Route::post('login',function(){ $creds=array( 'email' => Input::get('email'), 'password' => sha1(Input::get('password')) ); $auth = Auth::attempt($creds); dd($auth); Even though you can implement a Service provider as describe in this post , You can do it manually by with using other auth method This means you can do like so: //.... try{ $user = User::where('email', Input::get('email')) ->where('password', sha1

Laravel 5.3 - Is it possible to run php artisan command by clicking on a link/button

倖福魔咒の 提交于 2019-12-06 09:51:22
问题 So as the question says...is there a way to run php artisan command in background when user clicks on a link in web browser? For example i would like to make a button in my app for migrating migration files so when this button is clicked: <a href="/migrate" class="btn btn-primary">Migrate</a> i would like to run php artisan migrate in background. Is this somehow possible? 回答1: Sure you can! Just simply create a new route within your routes\web.php file. Then you can just simply call Artisan:

Registration error in Laravel

本秂侑毒 提交于 2019-12-06 07:31:24
I use the default auth/registration in Laravel 5.3. When I try to register new user I get error: FatalThrowableError in RegistersUsers.php line 33: Call to undefined method Illuminate\Auth\TokenGuard::login() I have made some changes in configuration Laravel: 'defaults' => [ 'guard' => 'api', 'passwords' => 'users', ], So, by default I use api guard The authentication driver api you are trying to use is TokenBased. That means the server will issue your client a Token on successful authentication using credentials. Then, client can present this token to server while making the request to

If the second page has one item, the pagination is not displayed in laravel 5.3

依然范特西╮ 提交于 2019-12-06 05:28:54
let's assume we have 11 items and we set 10 items per page so the second page will have 1 item, in this case the pagination in second page is not displayed but when add another item and the list becomes 12 and the second page has 2 items the pagination is displayed. Controller: $cities = City::orderBy('id', 'desc')->paginate(10); return view('cities.home', compact('cities')); View: <div class="panel-body"> <div class="table-responsive panel panel-sky"> <table class="table table-striped table-hover"> <tr> <th>#</th> <th>Name</th> <th>Created At</th> <th>Action</th> </tr> @foreach($cities as

Unable to connect to mysql on digitalocean using workbench over ssh

谁说我不能喝 提交于 2019-12-06 05:03:28
I have got my droplet set with the laravel app and database. Created my db while on putty ssh. Now when I am trying to connect to my mysql database as in image, i am getting error. Error: Authentication error, unhandled exception caught in tunnel manager, plese refer to logs for details. Note that my credentials are right, as that what I use to connect through putty. Any help on how can I see view my database? Got this solved like this. Turns out this is an ssh level issue. The digital ocean server doesn't have the support for the Kex algorithm as mentioned in the error the following can be