﻿{"id":337,"date":"2020-10-20T12:14:53","date_gmt":"2020-10-20T09:14:53","guid":{"rendered":"http:\/\/xn--e1agicip.xn--90ais\/?p=337"},"modified":"2020-12-22T20:07:52","modified_gmt":"2020-12-22T17:07:52","slug":"working-with-laravel","status":"publish","type":"post","link":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/2020\/10\/20\/working-with-laravel\/","title":{"rendered":"Working with laravel"},"content":{"rendered":"\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 Xampp:<\/p>\n\n\n\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 C:\\Windows\\System32\\drivers\\etc\\hosts \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441\u0430\u0439\u0442\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">127.0.0.1 laravel.test <\/pre>\n\n\n\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 c:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u043f\u0443\u0442\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;VirtualHost *:80&gt;\nServerName laravel.test\nDocumentRoot \"c:\/xampp\/htdocs\/laravel.test\/public\"\n&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u0439\u0442 \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e: http:\/\/laravel.test\/<\/p>\n\n\n\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438: \u043b\u0438\u0431\u043e \u043c\u044b \u0440\u0430\u0441\u043a\u043e\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 RouteServiceProvider &#8216;protected&nbsp;$namespace&nbsp;=&nbsp;&#8216;App\\\\Http\\\\Controllers&#8217;;&#8217; \u0438 \u0442\u043e\u0433\u0434\u0430 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043c\u043e\u0436\u043d\u043e &#8216;MainController@index&#8217;<\/p>\n\n\n\n<p>\u041b\u0438\u0431\u043e \u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 web &#8216;use&nbsp;App\\Http\\Controllers\\MainController&#8217; \u0438 \u0442\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 &#8216;Route::get(&#8216;\/users&#8217;, [MainController::class, &#8216;index&#8217;]);&#8217;<\/p>\n\n\n\n<p>\u0420\u0435\u0448\u0438\u043b \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u043e\u0432\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 (\u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u044b)<\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/63807930\/target-class-controller-does-not-exist-laravel-8\">https:\/\/stackoverflow.com\/questions\/63807930\/target-class-controller-does-not-exist-laravel-8<\/a><\/p>\n\n\n\n<p>\u0414\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0434\u043c\u0438\u043d\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n\n\n\n<ol><li>\u0417\u0430\u0432\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 users &#8211; admin (0\/1)<\/li><li>php artisan make:middleware IsAdmin<\/li><li>\u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <strong>routeMiddleware<\/strong>&nbsp;\u0444\u0430\u0439\u043b\u0430 <strong>app\/Http\/Kernel.php<\/strong> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c &#8216;admin&#8217; =&gt; \\App\\Http\\Middleware\\IsAdmin::class,<\/li><li>handel \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 IsAdmin.php \u043f\u0440\u0430\u0432\u0438\u043c: public function handle($request, Closure $next) { if (Auth::user() &amp;&amp; Auth::user()-&gt;admin == 1) { return $next($request); } return redirect(&#8216;\/&#8217;); }<\/li><li>\u0432 web.php \u0433\u0440\u0443\u043f\u043f\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0434\u043b\u044f \u0430\u0434\u043c\u0438\u043d\u0430 \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u0442\u0441\u044f: Route::group([&#8216;middleware&#8217; =&gt; &#8216;auth&#8217;, &#8216;middleware&#8217; =&gt; &#8216;admin&#8217;], function () { \/\/ });<\/li><\/ol>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0448\u044c \u0447\u0435\u0440\u0435\u0437 API, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c resource (https:\/\/laravel.com\/docs\/8.x\/eloquent-resources). \u042d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 &#8220;\u043e\u0431\u0440\u0435\u0437\u0430\u0442\u044c&#8221; \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 Xampp: \u0412 \u0444\u0430\u0439\u043b\u0435 C:\\Windows\\System32\\drivers\\etc\\hosts \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441\u0430\u0439\u0442\u0430: 127.0.0.1 laravel.test \u0412 \u0444\u0430\u0439\u043b\u0435 c:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u043f\u0443\u0442\u0438: &lt;VirtualHost *:80&gt; ServerName laravel.test DocumentRoot &#8220;c:\/xampp\/htdocs\/laravel.test\/public&#8221; &lt;\/VirtualHost&gt; \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u0439\u0442 \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e: http:\/\/laravel.test\/ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438: \u043b\u0438\u0431\u043e \u043c\u044b \u0440\u0430\u0441\u043a\u043e\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 RouteServiceProvider &#8216;protected&nbsp;$namespace&nbsp;=&nbsp;&#8216;App\\\\Http\\\\Controllers&#8217;;&#8217; \u0438 \u0442\u043e\u0433\u0434\u0430 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043c\u043e\u0436\u043d\u043e &#8216;MainController@index&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68],"tags":[80,81],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts\/337"}],"collection":[{"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":11,"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":353,"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts\/337\/revisions\/353"}],"wp:attachment":[{"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}