66use Symfony \Component \Process \Process ;
77use Symfony \Component \Process \Exception \ProcessFailedException ;
88use App \Log ;
9+ use Auth ;
10+ use App \User ;
911
1012class HomeController extends Controller
1113{
@@ -18,15 +20,22 @@ public function __construct()
1820 {
1921 $ this ->middleware ('auth ' );
2022 }
23+ public function welcome (){
24+ $ count = User::sum ('scans ' );
25+ return view ('welcome ' )->withCount ($ count );
2126
27+ }
2228 /**
2329 * Show the application dashboard.
2430 *
2531 * @return \Illuminate\Http\Response
2632 */
2733 public function index ()
2834 {
29- return view ('home ' );
35+ $ saves = Log::where ('user_id ' ,Auth::user ()->id )->get ();
36+ $ count = Log::where ('user_id ' ,Auth::user ()->id )->count ();
37+
38+ return view ('home ' )->withSaves ($ saves )->withCount ($ count );
3039 }
3140 public function script (Request $ request )
3241 {
@@ -37,13 +46,32 @@ public function script(Request $request)
3746 $ process ->run (function ($ type , $ buffer ){
3847 });
3948 $ echo = $ process ->getOutput ();
49+ $ source = parse_url ($ url );
50+ $ source = $ source ['host ' ];
51+ $ user = Auth::user ();
52+ $ user ->scans +=1 ;
53+ $ user ->save ();
4054 if ($ save ){
4155 $ log = new Log ();
42- $ log ->url = $ url ;
56+ $ log ->url = $ source ;
57+ $ log ->user_id =$ user ->id ;
4358 $ log ->output =$ process ->getOutput ();
4459 $ log ->save ();
4560 }
46- return view ('results ' )->withEcho ($ echo );
4761
62+ return view ('results ' )->withEcho ($ echo )->withSource ($ source );
63+
64+ }
65+ public function delete ($ id ){
66+ $ log = Log::find ($ id );
67+ $ log ->delete ();
68+ $ saves = Log::where ('user_id ' ,Auth::user ()->id )->get ();
69+ $ count = Log::where ('user_id ' ,Auth::user ()->id )->count ();
70+
71+ return view ('home ' )->withSaves ($ saves )->withCount ($ count );
72+ }
73+ public function saves ($ id ){
74+ $ saves = Log::findorfail ($ id );
75+ return view ('saves ' )->withSaves ($ saves );
4876 }
4977}
0 commit comments