File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Illuminate \Database \Migrations \Migration ;
4
+ use Illuminate \Database \Schema \Blueprint ;
5
+ use Illuminate \Support \Facades \Schema ;
6
+
7
+ class AddUserToLog extends Migration
8
+ {
9
+ /**
10
+ * Run the migrations.
11
+ *
12
+ * @return void
13
+ */
14
+ public function up ()
15
+ {
16
+ Schema::table ('youtube_logs ' , function (Blueprint $ table ) {
17
+ $ table ->foreignId ('user_id ' )->nullable ()->after ('id ' );
18
+
19
+ $ table ->foreign ('user_id ' )->references ('id ' )->on ('users ' )->onDelete ('SET NULL ' )->onUpdate ('CASCADE ' );
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Reverse the migrations.
25
+ *
26
+ * @return void
27
+ */
28
+ public function down ()
29
+ {
30
+ Schema::table ('youtube_logs ' , function (Blueprint $ table ) {
31
+ $ table ->dropConstrainedForeignId ('user_id ' );
32
+ });
33
+ }
34
+ }
Original file line number Diff line number Diff line change 10
10
use Illuminate \Http \Request ;
11
11
use Illuminate \Routing \Controller ;
12
12
use Illuminate \Support \Arr ;
13
+ use Illuminate \Support \Facades \Auth ;
13
14
use Illuminate \Support \Facades \File ;
14
15
use Illuminate \Support \Facades \Storage ;
15
16
use Illuminate \Support \Facades \Validator ;
@@ -106,7 +107,9 @@ public function convert(Request $request)
106
107
$ log ->title = $ video ->getTitle ();
107
108
$ log ->duration = $ video ->getDuration ();
108
109
$ log ->format = $ format ;
109
- //$log->user()->associate(Auth::user()) todo ?
110
+
111
+ if (config ('youtube-api.auth ' ) !== null )
112
+ $ log ->user ()->associate (Auth::user ());
110
113
111
114
$ log ->save ();
112
115
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace MichaelBelgium \YoutubeAPI \Models ;
4
4
5
+ use Exception ;
5
6
use Illuminate \Database \Eloquent \Model ;
6
7
7
8
class Log extends Model
@@ -11,4 +12,12 @@ class Log extends Model
11
12
public $ timestamps = ["created_at " ];
12
13
13
14
const UPDATED_AT = null ;
15
+
16
+ public function user ()
17
+ {
18
+ if (config ('auth.providers.users.model ' ) !== null )
19
+ return $ this ->belongsTo (config ('auth.providers.users.model ' ));
20
+ else
21
+ throw new Exception ('No user provider model defined. ' );
22
+ }
14
23
}
You can’t perform that action at this time.
0 commit comments