laravel

Duplicate Entry when using firstOrCreate on Laravel?

╄→尐↘猪︶ㄣ 提交于 2021-01-29 15:08:47
问题 This is my Controller foreach ($dataOrder['items'] as $rowJubelio) { DataOrderDetailEcommerce::firstOrCreate([ 'order_id' => DataOrderEcommerce::firstOrCreate([ 'orderid'=> $invoice, 'cust_name'=> ucwords($cust_name), 'province'=> $province, 'city'=> $city, 'district'=> $area, 'zipcode'=> $zipcode, 'phone'=>$phone, 'fleet_id'=> $fleet, 'ecommerce_id'=> $ecommerce, 'date_add'=>date('Y-m-d'), 'no_resi'=> $no_resi, 'email'=> $email, 'order_time'=> $transactionDate ])->orderid, 'sku_id'=>

Create and Insert Many-to-Many Relationships in Laravel

霸气de小男生 提交于 2021-01-29 15:07:40
问题 First of all, i'm a beginner and trying to learn all i can. So if i have mistakes please correct me. So, i am working on a laravel project. I've got two models; drugs and interactions. What i am struggling is, I want to add two drugs and one interaction in one form. But also, i want to check if the drug has inserted already to avoid duplicate data. Here are my models: class Drug extends Model { //Table Name protected $table = 'drugs'; //Primary Key public $primaryKey = 'id'; //Timestamps

Responsive File Manager and TinyMCE

老子叫甜甜 提交于 2021-01-29 14:44:49
问题 I'm using Responsive File Manager 9.14.0 with tinyMCE v 5 in a Laravel v 6 App - I followed a tutorial in doing the setup. Everything works fine apart from when the button 'Start upload' is clicked - I get this error: Unexpected token < in JSON at position 0. This is displayed in the page on the back end in the php error log I get these two errors. [05-Mar-2020 12:08:17 Europe/Rome] PHP Notice: Trying to access array offset on value of type null in /var/www/html/laratest/public/tinymce

Laravel : I received song file “form-data” from one of API then i need to forward that file to another API. Any idea to forward?

故事扮演 提交于 2021-01-29 13:50:54
问题 Laravel project 1 controller how to forward file to API-2 Input::file('songFile')->move("/tmp", $newname); i used this function and store tmp location then how to use this tmp location file and forward? 回答1: In order to post a file to API endpoint, you can follow the following code. try{ $path = 'var/www/html/myproject/public/file.txt';//your file path if (!empty($path) && file_exists($path)) { $guzzleResponse = $client->post($api_url, [ 'multipart' => [ [ 'name' => 'file',// it is the name

Laravel Model creation override

可紊 提交于 2021-01-29 13:48:22
问题 In my Laravel project, I have different user types that all have a base User model. Here's a brief idea of the database topology: users: - id - name - email students: - age - user_id teachers: - budget - user_id employee: - is_admin - user_id In my case, each of Student , Teacher , Employee has their own User . But if I want to make a new Student for example, I have to make both a Student and User model. I'm aware of the Observers pattern in Laravel which can make this job easier, but I'd

Many to Many to MorphToMany Relationships

自古美人都是妖i 提交于 2021-01-29 13:42:47
问题 I have an Exam , Question and Tag (Spatie/laravel-tags package) models. An Exam consists of many Questions (Many to Many), and Question has many Tags (MorphToMany). I would like to have a method on the Exam model to get all the tags of Exam through its associated questions, such that $exams→tags() returns all the tags from associated questions belonging to the exam. Can anyone point me towards what may be the best course to take in order to achieve this? 回答1: If you have proper described

Laravel Passport: How to validate client IP when requesting API

半腔热情 提交于 2021-01-29 13:14:04
问题 I'm using Laravel Passport as my API authentication mechanism. Everything is working as expected, but i need to add an extra validation for each request. The idea is to validate the client IP Address alongside the access_token that is sent to the server. Any idea how i can accomplish this? UPDATE: I want to check if the IP used in the authentication (when the user logged in) is the same as the one doing the requestes. If the IP is different, the client must login again. 回答1: Ip address could

Laravel 7 filters

最后都变了- 提交于 2021-01-29 13:13:20
问题 I have successfully created a logging and registration system! I get to the part where I need to do the sign out option. My course I bought at Udemy is a bit old so I don't have a file called filters.php I searched on the internet to find a file called filters.php and found one post saying Middleware was used instead of filter.php How to create a Sign out option now using Middleware ? Web.php Route::group(array('before' => 'auth'), function()){ } 回答1: You don't need to create the sign out

Laravel - Favourite / Un-Favourite button

泄露秘密 提交于 2021-01-29 13:11:36
问题 I'm trying to create a favourite / un-favourite button for items. The button needs to be toggable so that when the user first clicks it, the item is added to favourites, the next time they click it the item should be un-favourited. It should also remember all the items the user has already favourited and display the button differently. Here is what I currently have, I loop through all the items and display the delete or add button depending if they have the item favourited: @foreach($items as

CSS File not loading into PHP Laravel application with Google App Engine and runtime php72

跟風遠走 提交于 2021-01-29 13:02:22
问题 I try to run a standard installation of a Laravel 5.8.x application with its own CSS file on the Google App Engine with standard configuration (runtime: php72). The page is displayed, but the CSS file public/css/main.css is not loaded. There is a 404 error in the browser. This is my app.yaml code: runtime: php72 service: default env_variables: APP_KEY: xxxxx APP_STORAGE: /tmp VIEW_COMPILED_PATH: /tmp APP_ENV: production APP_DEBUG: false CACHE_DRIVER: database SESSION_DRIVER: database ... I