laravel-5

How with $faker->word get unique value?

微笑、不失礼 提交于 2021-01-28 07:44:06
问题 In laravel 5.8 app I make tests and adding new user for any tests I encountered that line $loggedUser= factory(User::class)->create(); raise error : Doctrine\DBAL\Driver\PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Username pariatur' for key 'users_username_unique' with factory defined : $factory->define(App\User::class, function (Faker $faker) { $username= 'Username ' . $faker->word; return [ 'username' => $username, I do not clear database, but how to

Laravel crash on init with error 500 (no additional info)

徘徊边缘 提交于 2021-01-28 07:08:10
问题 I have some problems with deploying app to a shared host. What i did till now: copy all public files to public_html/website/my-api copy all laravel system files to public_html/laravel checked rights corrected my-api/index.php require and require_once to a laravel/bootstrap/autoload.php laravel logs are empty no data in apache logs are empty no data in my webhosting is Hetzner hosting After some debugging it crashes here: $response = $kernel->handle( $request = Illuminate\Http\Request::capture

Creating a sign up token for Laravel app from separate frontend app

那年仲夏 提交于 2021-01-28 03:13:16
问题 I'm creating an Angular app with a separate Laravel backend. I want to User auth, specifically User registration. I'm getting the following errors: Error from frontend app: No 'Access-Control-Allow-Origin' header is present on the requested resource. Error when trying to create new user from DHC: Endpoint: my_apps_api.localhost/api/auth/register Post Data: { "username" : "myusername" "password" : "12345" } TokenMismatchException in VerifyCsrfToken.php I think this is because I need to

Send email from contact form in Laravel 5 using jQuery AJAX

橙三吉。 提交于 2021-01-27 22:50:24
问题 I have contact form in Laravel blade: <div id="contactform"> <meta name="_token" content="{{ csrf_token() }}" /> <ul> @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> {{ Form::open(array('route' => 'contact_store', 'id' => 'contact', 'name' => 'contact')) }} <input type="text" id="firstName" name="firstName" placeholder="{{ trans('index.first_name') }}" class="required" /> <input type="text" id="lastName" name="lastName" placeholder="{{ trans('index.last_name') }}"

Laravel get data based on foreign key

让人想犯罪 __ 提交于 2021-01-27 17:24:40
问题 So I have 2 tables, TABLE1 and TABLE2. They are linked throug Eloquent: TABLE1 has many TABLE2's, and TABLE2 has one TABLE 1. They are linked with foreign keys as such: in TABLE2 table1_id -> links to -> TABLE1 id. How do I retrieve the entire table data or TABLE 2, + replace table1_id with a column of table1 (let's say by booktitle for example)? Sorry for the abstraction, but this is the best way I can explain it? :D 回答1: The easiest way is to make use of Eloquent's eager loading and fetch

Laravel get data based on foreign key

邮差的信 提交于 2021-01-27 17:21:22
问题 So I have 2 tables, TABLE1 and TABLE2. They are linked throug Eloquent: TABLE1 has many TABLE2's, and TABLE2 has one TABLE 1. They are linked with foreign keys as such: in TABLE2 table1_id -> links to -> TABLE1 id. How do I retrieve the entire table data or TABLE 2, + replace table1_id with a column of table1 (let's say by booktitle for example)? Sorry for the abstraction, but this is the best way I can explain it? :D 回答1: The easiest way is to make use of Eloquent's eager loading and fetch

public_path() returning results with backslash instead of forward slash

折月煮酒 提交于 2021-01-27 13:12:21
问题 I am writing, <?php echo public_path();?> It returns results with backlashes instead of forward slashes. I expected forward slashes. 回答1: public_path() uses DIRECTORY_SEPARATOR which depends on your OS. To change it to backslashes, you can use str_replace(): str_replace('\\', '/', public_path()) Update For loading assets, use the assets() helper. 来源: https://stackoverflow.com/questions/48289384/public-path-returning-results-with-backslash-instead-of-forward-slash

Can't connect to database with laravel 5

≡放荡痞女 提交于 2021-01-27 07:16:43
问题 I'm trying to connect to my mssql database with laravel 5 but it's not working. I've tried to connect with different mssql databases so it's not a firewall issue. Also my credentials are correct. I found on google that you need SQL Server Native Client 11.0 and I've already installed that. This is my connection array in config/database.php: 'sqlsrv' => [ 'driver' => 'sqlsrv', 'host' => env('nvt'), 'database' => env('nvt'), 'username' => env('nvt'), 'password' => env('nvt'), 'charset' => 'utf8

Any way to dispatch a closure in laravel 5?

十年热恋 提交于 2021-01-27 07:13:57
问题 In laravel 4, I could push a closure onto the queue with queue::push(function...) , but this no longer works in laravel 5. Instead, it appears that I have to make a custom Job class for every function that I want to push onto the queue. Since the functions I want to be pushing are only a couple of lines long, and are only ever used in exactly one place, it really seems like a waste of time and space to be writing up a full class for every case. The best "solutions" I can currently think of,

Any way to dispatch a closure in laravel 5?

筅森魡賤 提交于 2021-01-27 07:11:15
问题 In laravel 4, I could push a closure onto the queue with queue::push(function...) , but this no longer works in laravel 5. Instead, it appears that I have to make a custom Job class for every function that I want to push onto the queue. Since the functions I want to be pushing are only a couple of lines long, and are only ever used in exactly one place, it really seems like a waste of time and space to be writing up a full class for every case. The best "solutions" I can currently think of,